using UnityEngine; using UnityEngine.UI; /// /// Assign this script to the indicator prefabs. /// public class Indicator : MonoBehaviour { [SerializeField] private IndicatorType indicatorType; private Image indicatorImage; private Text distanceText; /// /// Gets if the game object is active in hierarchy. /// public bool Active { get { return transform.gameObject.activeInHierarchy; } } /// /// Gets the indicator type /// public IndicatorType Type { get { return indicatorType; } } void Awake() { indicatorImage = transform.GetComponent(); distanceText = transform.GetComponentInChildren(); } /// /// Sets the image color for the indicator. /// /// public void SetImageColor(Color color) { indicatorImage.color = color; } /// /// Sets the distance text for the indicator. /// /// public void SetDistanceText(float value) { distanceText.text = value >= 0 ? Mathf.Floor(value) + " m" : ""; } /// /// Sets the distance text rotation of the indicator. /// /// public void SetTextRotation(Quaternion rotation) { distanceText.rectTransform.rotation = rotation; } /// /// Sets the indicator as active or inactive. /// /// public void Activate(bool value) { transform.gameObject.SetActive(value); } } public enum IndicatorType { BOX, ARROW }