TRIGGER EVENT NOT WORKING! :'(

Hey there!! I have been following a tutorial on Youtube on how to make a “holographic UI” appear on a distance trigger. I will link the tutorial here:

However this script does not seem to allow me to create the trigger event. Nothing happens, the animation just loops through.

public float minDistance = 2;
public bool show = false;

protected Animator[ ] children;

void Start () {

children = GetComponentsInChildren();
for (int a = 0; a < children.Length; a++)
{
children[a].SetBool(“Show”, true);
}
}

// Update is called once per frame
void Update () {
Vector3 delta = Camera.main.transform.position - transform.position;
if (delta.magnitude < minDistance)
{
if (show) return;
show = true;
for (int a = 0; a < children.Length; a++)
{
children[a].SetBool(“Show”,true);

}
}

else
{
if (!show) return;
show = false;
for (int a = 0; a < children.Length; a++)
{
children[a].SetBool(“Show”, false);
}
}
}
}

I am used the latest version of unity.

Whats wrong here? :frowning:

Could be a problem with the animator setup. We can’t go through everything for you. You’ll just have to go back and review and see what is different. Also, read the part about code tags at the beginning of this forum.

Try this:

also set this :
public float minDistance = 2f;

void Update()
{
float dist = Vector3.Distance(Camera.main.transform.position, transform.position);
if (dist < minDistance)
{
if (show) return;
show = true;
for (int a = 0; a < children.Length; a++)
{
children[a].SetBool("Show",true);

}
}

else
{
if (!show) return;
show = false;
for (int a = 0; a < children.Length; a++)
{
children[a].SetBool("Show", false);
}
}
}

Also, please attach screenshots of the hierarchy panel and show us that your gameObjects have the animators on them.