- Home /
Trouble with triggers and colliders
Hi, I'm having some issues with the triggers and collisions in my game... In the image below, there are 6 objects: A, B, C, D, E and F The idea is that once object A collides with object E, it sends the information to object C, and same goes for the other side. When B collides with F, it sends the information to object D.
What ACTUALLY happens, is that once A touches object E, it sends the info both to C and D.
Objects A and B are the same prefab (Different names tho), and have the same script. object A is a child of C, and B is a child of D.
Please help me I've tries everything! :(
It would help to show people the collision code and the place where messages are sent to other objects
Ok here's the script that's attached to objects A and B. CellScript is the script that's attached to C and D Energy is the tag of E and F.
From my understanding, what needs to happen is when A touches E (E is tagged "Energy"), is reads is the object "energyObject" of his parent exists, if not, than the hit object (E) becomes "energyObject".
function OnTriggerEnter (coll : Collider)
{
if ((this.transform.parent.GetComponent(CellScript).energyObject == null) &&(coll.gameObject.tag == "Energy"))
{
this.transform.parent.GetComponent(CellScript).energyObject = coll.gameObject;
this.transform.parent.gameObject.rigidbody.is$$anonymous$$inematic = false;
}
}
Answer by Addyarb · Nov 18, 2014 at 01:03 AM
I hope I understand your issue correctly. If you are looking to get more discreet collisions, try using:
if(col.transform.tag == "Object_A"){
//Do the collision
}
else{
if(col.transform.tag == "Object_B"){
//Do the other collision... etc.
}
}
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Have child ignore parent's tag? 1 Answer
Parent Script accessing Child components 1 Answer
OnTriggerEnter not being called with multiple colliders 1 Answer