I need to check when an object enters a collider attached to another game object. I have set the collider through the inspector as a public variable. I tried using the standard onTriggerEnter function but passing the other collider in, however this doesn’t seam to work.
Is there a way to detect gameObjects entering colliders attached to other game objects?
public SphereCollider theCollider;
// Check if GameObject enters
void OnTriggerEnter (Collider theCollider) {
//Do Stuff
}
Could you add that as an answer so I can accept it? it was the best way to do it.. the other guy who answered doesn't seam to have understood the question...
Hi, I would have the OnTriggerEnter(or collision variant) function attached to the object that you want to detect the event on. When triggered call a function on the script/object you need this information for. Create a reference to the main script at the start of your collider scripts.
you need to set a tag name to the object you want to collide with your collider.
If you have allot of collisions i suggest using switch instead of if statements.
I want to detect everything that collides with the collider, so the tag thing won't help much. My problem is that this approach doesnt seam to work when trying to detect thing from a collider attached to another game object...
Could you add that as an answer so I can accept it? it was the best way to do it.. the other guy who answered doesn't seam to have understood the question...
– cheadleand