1
votes

It is my compulsion to use rigidbody and box collider to all collided gameObjects (Where I have to detect collision)., i.e., I got some really big trouble as two object collide with each other, 2 times onTriggerEnter play which I surely don't want to do. Is there any way to control it.? Without removing Script and rigidbody to any object.

void OnTriggerEnter(Collider collidedAGV)
    {

     if (collidedAGV.tag == "cib" )
     {
    }
}
1
Hi Mohammad - in the first instance you should familiarize yourself with the Layers feature in Unity -- it's great. In fact you have to use it every time.Fattie
u mean i need to change the layer then, check triggger but i will be unable to reset it. i guessMuhammad Faizan Khan
it's worth mentioning that, in theory, one thing you can do in that type of situation is get the InstanceID of both and only act if you are the lower ID! i wouldn't really recommend that as a solution here docs.unity3d.com/ScriptReference/Object.GetInstanceID.htmlFattie
why u will not recommendMuhammad Faizan Khan
I have use layer it working fine but i didn't test it correctly! so maybe layer solution look feasible but have to test vigorouslyMuhammad Faizan Khan

1 Answers

0
votes

You could either change the tag of one of the objects, or make the script also check the name of object it has collided to:

void OnTriggerEnter ( Collider collidedAGV )
{
    if (collidedAGV.tag == "cib" && collidedAGV.name == "collided object name")
    {
        //Do stuff
    }
}