Joshua Gonzales
Joshua Gonzales

Reputation: 15

Unhide a Game Object when triggered an another game object

so i have 2 game objects . the first game object is setActive(false); and the second game object is the one when i triggered, the first game object must setActive(true); but i cant seem to do it .. im just a beginner in Unity

#pragma strict
function Start () 
{
    GameObject.Find("jumpImage").SetActive(false);
}

function OnTriggerEnter(col:Collider)
{   
    if(col.tag=="Player")
    {
        GameObject.Find("jumpImage").SetActive(true);
    }       
}

Upvotes: 1

Views: 56

Answers (1)

Landern
Landern

Reputation: 374

GameObject.Find only finds "ACTIVE" game objects which you can see in the documentation for GameObject.Find.

With that said, if you're referencing the same GameObject between Start and the OnTriggerEnter functions, you might as well store a reference after you first find it.

#pragma strict

var jumpImageGO : GameObject;

function Start () 
{
    jumpImageGO = GameObject.Find("jumpImage");
    if (jumpImageGO != null)
        jumpImageGO.SetActive(false);
}

function OnTriggerEnter(col:Collider)
{
    if(col.tag=="Player")
    {
        jumpImageGO.SetActive(true);
    }       
}

Upvotes: 1

Related Questions