I have some gui text constrained to other gui elements (not parented). And I’d like them to be hidden when their constraining elements (target) are disabled. I was hoping that checking the target is true would be enough, apparently not!
How should I do a check to see if the target is disabled?
using UnityEngine;
using System.Collections;
public class PinTransform : MonoBehaviour {
public Transform target;
public Vector3 offset;
private CanvasRenderer guiVis;
// Use this for initialization
void Start () {
this.guiVis = GetComponent<CanvasRenderer>();
this.guiVis.SetAlpha(0f);
}
// Update is called once per frame
void LateUpdate () {
if (target)
{
transform.position = target.position + offset;
this.guiVis.SetAlpha(1f);
Debug.Log("I can see it.");
}
else
{
this.guiVis.SetAlpha(0f);
}
}
}