- Home /
Help with OnTriggerEnter Issue
Hi im making a sidescroller game. When you fall off the level you die and it resets the level with this script here
`#pragma strict
var player : GameObject;
function OnTriggerEnter(player : Collider){
if(player.tag =="Player");
Destroy(player.gameObject);
Application.LoadLevel(Application.loadedLevel);
}
`
This is all fine and dandy. The issue is I have movable cubes you can push around. Now if you push one of those cubes off the edge instead of the PlayerRespawn collider ignoring it and only deleting objects with the tag "Player" it deletes the cube and reloads the level. If you guys can see any errors in my code can you please help? Or any advice with how to do this in a more efficient way would be much appreciated. If you have any questions about my code in helping you understand it please ask. Thanks a lot for all of your help, it's a strong programming community that makes games that much better.
Answer by whydoidoit · Feb 13, 2014 at 05:26 AM
I have a friend who once awoke from a nightmare shouting "Semi-colon" - you have the same problem :)
Your if statement does nothing (because of the semi-colon) what you want is this:
function OnTriggerEnter(player : Collider){
if(player.tag =="Player") {
Destroy(player.gameObject);
Application.LoadLevel(Application.loadedLevel);
}
}
I've been program$$anonymous$$g for eight years. I am so mad, happy, depressed, and feel like a baby penguin when their mother has been eaten by a seal. I hate my self. Thank you. I shouldn't make such a stupid mistake. I am so so so just so I cant even explain it. Its just Idk. I am broken just like my game used to be.