- Home /
Unity2D: Renderer off/ on by triggers
Basically, I have a sprite which resembles a torch. If the torch is over the trap on the floor then it will turn on the renderer however when I move the torch off the trap, the traps renderer is still on and should turn off. Can anyone help me with this?
#pragma strict
private var CanShow : boolean = false;
function Update()
{
if(CanShow)
{
this.GetComponent(Renderer).enabled = true;
}
if(!CanShow)
{
this.GetComponent(Renderer).enabled = false;
}
}
function OnTriggerEnter2D(other : Collider2D)
{
if(other.tag == "Torch")
{
CanShow = true;
}
}
function OnTriggerExit2D(other : Collider2D)
{
if(other.tag == "Torch")
{
CanShow = false;
}
}
Comment