- Home /
OnTrigger Box Collider Doesn't Work?
Hello, I am making a capture the flag type game and i set the box collider of my flag to istrigger. This is my OnTriggerEnter script: var player;
function OnTriggerEnter (theTrigger : Collider){
if (theTrigger == player){
SpasShoot.spasClipSize = 30;
player.getComponent (flagCarrier).hasFlag = true;
}
}
However my player runs straight through the flag and nothing that was supposed to happen happened. Does anyone know how I can fix this problem? Thanks a lot for the help!
Answer by adrenak · Sep 16, 2012 at 05:12 PM
I guess that this would be the right code :
if (theTrigger.gameObject.tag == "player"){ //or "Player"?
SpasShoot.spasClipSize = 30;
theTrigger.gameObject.GetComponent(flagCarrier).hasFlag = true;
}
I hope this helps!
Vatsal
You should be checking something specific about the game object. You can't just do if(theTrigger.gameObject == (whatever) it has to be like if(theTrigger.gameObject.name == "Player") or if(theTrigger.gameObject.tag == "Player") or something like that. You have to specify what aspect of the game object you're checking.
yeah, as wilco64256 pointed out, you can check for the tag or name of the colliding object
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
AI GameObjects Go Through Walls? 1 Answer
Object Collider problem, objects going through walls? 1 Answer
Collision Problem with Rigidbody? 1 Answer
Aiming down a gun 4 Answers