- Home /
Checking for collision of another gameObject with another trigger
I hope my title isn't too confusing...basically what I want to do is check if "Object Collision A" collided with "Trigger B" from a script attached to "Object C". So both "Object A" and "Trigger B" don't have any scripts attached to them, only "Object C" does.
Thanks in advance!
Answer by Goody! · Jan 30, 2011 at 07:07 PM
You can test in script against either the name of the object or the tag. Do a search for collider/ name/tag in the unity docs for how.
But you may a well attach that same script to each trigger. Then I think u can do a if this.name "triggername" and collider.name then do whatever.
Thanks for your answer Goody, I know it would be much easier to attach the script to each Trigger, but if I'm gonna have let's say 100 triggers out there, I would rather check for collision from 1 main script. I know how to test in script against the object name or tag, but how do I test for collision between Object A and Object B from Object C? Basically what i need to do is something like this:
if (ObjectA.Collider collides with ObjectB.Collider) {doSomething()}...but neither ObjectA and ObjectB have this script attached to them.
You can have just one script on all of the triggers then test which of the triggers is being triggered and act accordingly, i believe. Like, if This.name == triggerA and collider.name == this then do whatever.
If you have that many triggers I'm guessing you are going to need to manage them anyways.
bit late but you will have to use update not oncollision as the oncollision is for what ever that script is on. so if u collide with it and the script is on something else it aint gunna do anything because the function cant run, hence its cheaper to use on collision but more but a bit more annoying