0

I'm new to coding so I have no idea what I'm doing besides what I've had to do in like... the last three days. I just want the player to walk into a collider to trigger a Canvas UI, and then have the Canvas disappear when you exit the collider. Here is my code so far:

// JavaScript source code

function OnTriggerEnter(Col : Collider)
{
    if(Col.tag == "Player")
{
    myCanvas.active = true;
}

}

function OnTriggerExit(Col : Collider)
{
    if(Col.tag == "Player")
    {
        myCanvas.active = false;
    }

}

Even though I didn't get any errors and it plays, I'll enter the collider area and the Canvas won't show up, and when I exit the collider it's like it exits out of play mode... Help, please?

1 Answer 1

1

I'd recommend you get the GameObject that the Canvas component resides on. Set this object to inactive.
canvasObj.SetActive(false);

http://docs.unity3d.com/ScriptReference/GameObject.SetActive.html

If you want to enable/disable the component (e.g. myCanvas is a reference to a Canvas) you need to use .enabled

https://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.