Hello, I am trying to make a box so that when you enter you die (load a level called “Dead”) and I can’t just do that with a simple OnTriggerEnter script because I also have coins and I only want to die when I hot the box with a tag “Fire” here is what I was trying but it didn’t work
var guy : Transform;
function Update () {
if (guy.transform.position.tag == "Fire") {
Application.LoadLevel("Dead");
}
}
Simply check the tag of the trigger you hit:
function OnTriggerEnter(col : Collider){
if(other.tag == "Fire")
Application.LoadLevel("Dead");
else if(other.tag == "Coin")
PickUpCoin();
}
However i would recommend to have the script on the box and use:
function OnTriggerEnter(other : Collider){
if(other.tag == "Player")
Application.LoadLevel("Dead");
}
Both will work but with the first approach you will end up with tons of else if statements in the long run.