- Home /
A trigger to happen only once.
Hi! I created a code block that if you hit the colliders, they will be colored red. Now, how can I make that if a collider is hit, the other triggers will not happen anymore? Here are my codes.
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.collider.gameObject.name=="ID331"){
hit.collider.renderer.material.color = Color.red;
}
else if (hit.collider.gameObject.name=="Collider1"){
hit.collider.renderer.material.color = Color.red;
}
}
Thanks!
Comment
what do you mean by other triggers , triggers on other game objects or this game object that this script is attached to
Answer by Lex_87 · Sep 19, 2014 at 10:49 AM
var _triggerHasPassed : bool;
function OnControllerColliderHit(hit : ControllerColliderHit) {
if (_triggerHasPassed)
return;
if(hit.collider.gameObject.name=="ID331"){
hit.collider.renderer.material.color = Color.red;
}
else if (hit.collider.gameObject.name=="Collider1"){
hit.collider.renderer.material.color = Color.red;
}
_triggerHasPassed = true;
}
if return line works, it will work, try printing the bool every time to see it's state. and print if..theboolistrue...print(wastrue);
so you have some concept of seeing into the code you have, checking it, beco$$anonymous$$g master of the code.
Your answer