OnCollisionEnter Function from 3rd party Object?

Hi all.

Ok here is the scenario. Lets say I have 3 Objects in my scene, A B and C.

For what ever reason I want to ask Object A to detect a collision between object B and C without putting script on object B or C.

So if I place:

function OnCollisionEnter(collision : Collision) {

print(collision.gameObject.tag);

}

on Object A, it would of-cause print the tag of what ever object A collided with. But I want to keep the script on Object A and I want it not to detect the A collider but the collider on Object B to see if it hits C.

Any ideas?

2 Answers

2

It's not possible, sorry.

I personally would use a "game manager" script to achieve such a thing( or singleton, etc).

By this i mean a persistent script on an empty that can check for, and/or be sent variable registered in objects within the scene.

So, object B could send a variable to the game manager when object C collides with it, or the game manager would be listening for a variable change on object B due to the collision triggering it. And then, at your discretion, the game manager could send that changed variable to object A, or object A could be listening for the variable change in the game manager script.

If you aren't familiar with game managers, IMO, they're invaluable for communicating data to and from scene objects behind the scenes , and throughout all of the actual scenes in your app/game, staying active even when new scenes are loaded.

thanx for your time guys. yes I am using a "game manager" I have an empty game object that is called "Game Controller" all script is on it and it controls all objects in the scene, and I have not had to ad any scripts to the other object in the scene till I got to the collisions. thats why I asked. But yes, sending variables is what I ended up resorting to.

I dont mean to be rude, but since I mentioned the game manager, and it does achieve(in some form) what you are looking for, it would be most appreciated if you would thumbs up my answer, would really help me out, thanks.