- Home /
Question by
Manco Capac · Feb 03, 2013 at 03:31 PM ·
collidertriggercolliders
Multiple OnTriggerEnter in one script
I have multiple triggers in one gameObject, and would like them to trigger separately. I have no Idea how to do this... :-p
I have a script:
function OnTriggerEnter (other : Collider) {
if(DamCtrl.prevSpeed >= 5){
dam1.renderer.enabled = true;
cri1.renderer.enabled = false;
}
}
but I'll need more of the same functions. It'd be great if I could find which object the collider is attached to (to put in an if statement), as I don't want tags...
GN
Comment
Best Answer
Answer by fafase · Feb 03, 2013 at 03:46 PM
You can have each collider to be attached to different empty game objects. Then all are attached to a root game object. Assigning unique index to each you can know which is colliding. Then you have a dictionary to figure out which object is which
function OnTriggerEnter(){
transform.root.SendMessage("CollisionDetected", index);
}
then on the root object
function CollisionDetected(ind:int){
var obj = dictionary[ind];
}
Then you know what object is calling.Well I do not know exactly what you plan on doing but maybe that will give you a lead.