- Home /
Check if trigger collider is touching other trigger collider
To keep this short I have four objects and they all have specific tags, how would I check to see if any of these objects are touching another certain object and if so reposition them outside of that object so any of the four objects wont be inside that certain object when they spawn or at any point in the game.
All the objects have specific tags and colliders with the "is trigger" on.
Answer by AndyMartin458 · Jul 24, 2014 at 05:51 PM
As a quick note. You might get more performance out of giving all four of the objects the same tag. Something like this should work.
void OnTriggerEnter(Collider other)
{
if(string.Compare(other.gameObject.tag, "MyTag") == 0)
{
//Do Something
}
}
Could you please explain how this works exactly? @Andy$$anonymous$$artin458
Answer by saru15 · Apr 03, 2015 at 05:22 AM
Although @AndyMartin will works but this is i'll do it==>
void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("MyTag"))
{
//TODO: Something
}
}
In this other is the gameObject in which your gameObject will collide and MyTag is the tag of the object in which this script is attached to . .