Reputation: 1
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?
Upvotes: 0
Views: 41
Reputation: 83
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
Upvotes: 1