How to add many OnCollisionEnter in only one Script?

I want to try a project that only have one Script file (like AS3), so everything is done but when I imagine about collision, I don’t know what must I do. I read everywhere in Google just found OnCollisionEnter but it need to attach the script to one object, that I want is OnCollisionEnter in void Update and can link object like Ball that only get that OnCollisionEnter.
I can add multiple object to be attached in one script with public GameObject anyObject;
Didn’t Understand? Just add a comment :slight_smile:

The docs say it’s MonoBehaviour.OnCollisionEnter. This means, it’ll only detect collisions of the current object the script is attached to. It will not detect collisions on other gameObjects.


yea if your saying you want 1 script where you tell it what to do if a ball collides and then what to do as well if a box does and also if a player does.

All in one script. Nope.
Also that is simply bad programming from an object oriented point of view.

Each object should deal with it’s own self.

With the way your talking about designing it the ball doesn’t work unless this script that deals with 30 different objects collisions is included.

Thats like me saying i’d like a calculator that does addition and you saying I can’t give you that unless it also does division graphing and provides home phone service.

In as much as possible objects should be self contained and they should be able to be taken out and put in and not break the entire thing. Minimize the amount of dependencies you have.