Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

Leaderboard


Popular Content

Showing content with the highest reputation on 10/27/2017 in all areas

  1. 1 point
    A little script which I did to help player to find some goals in game. You can set different features (alpha threshold, offset, clambing, etc). I use it in my project Azymuth. How it works? In your Canvas, add an image, put the script on it, set your target... It could be useful in your projects so as to localizate a bomb or an enemy, an exit door, a dropped pack, etc ++ using UnityEngine; using System.Collections; using UnityEngine.UI; public class HUD : MonoBehaviour { RectTransform myRectTransform; // UI Camera mainCamera; Color alpha; // temp color public Transform currentTarget; // target public bool clampToScreen = true; // display offscreen target or not public float threshold = 10; // sprite alpha control public Vector3 offset; [SerializeField] Vector2 clampBorderSize; void Awake() { myRectTransform = GetComponent<RectTransform>(); mainCamera = Camera.main; // find the camera } void Update() { // if the target has been destroyed, it disables the script and erases image if (currentTarget == null) { myRectTransform.GetComponent<Image>().color = new Color(0, 0, 0, 0); this.enabled = false; } Vector3 noClampPosition = mainCamera.WorldToScreenPoint(currentTarget.position + offset); // modify alpha according Z alpha = myRectTransform.GetComponent<Image>().color; alpha.a = noClampPosition.z / threshold; myRectTransform.GetComponent<Image>().color = alpha; Vector3 clampedPosition = new Vector3(Mathf.Clamp(noClampPosition.x, 0 + clampBorderSize.x, Screen.width - clampBorderSize.x), Mathf.Clamp(noClampPosition.y, 0 + clampBorderSize.y, Screen.height - clampBorderSize.y), noClampPosition.z); // display sprite on screen - or not myRectTransform.position = clampToScreen ? clampedPosition : noClampPosition; } }
  2. 1 point
    Watch this video https://youtu.be/v1_MqLoMvKU
  3. 1 point
    okay, make an empty game object in the canvas and move the hud elements into the game object. You will apply it to the game object.
  4. 1 point
    Vector3.Distance(target, player.position).ToString() you just tell the ui the distance
  5. 1 point
    Maybe this will help, This is what I use for mine, Be sure to name the script "HUDMovement" in C#. //Embers Studio using System.Collections; using System.Collections.Generic; using UnityEngine; public class HUDMovement : MonoBehaviour { public float HUDTiltAngle = 0.005f; public float HUDSmoothComplexity = 1f; void Update() { float tiltX = Input.GetAxis("Mouse X") * HUDTiltAngle; float tiltY = Input.GetAxis("Mouse Y") * HUDTiltAngle; Quaternion target = Quaternion.Euler(tiltY, tiltX, 0); transform.localRotation = Quaternion.Slerp(transform.localRotation, target, Time.deltaTime * HUDSmoothComplexity); } }
×
×
  • Create New...