Newb Question: Are there any limitations with creating a single script for controlling all game collisions

Hi,

With exception of my new adventure creating basic 2D games using Unity3d i am fairly new to the world of coding. At the moment I’m focusing on C#

Is it possible/worth creating a single script which is designed to control all collision actions in a simple 2D game? Does anyone have any experience with this?

What are the limitations?

Is it possible to detect a collision between object A and object B triggering an action?

Is it bad practice to create a single script?

Thanks

No, you can’t have a single “Collision Manager” script. When Object A collides with Object B, both A and B are sent a collision message, which either one can act upon by implementing the appropriate OnCollisionEnter, OnTriggerEnter etc. etc. methods. However, there’s no global collision event produced that Object C can subscribe to.

(Besides, this is generally considered bad practice anyway - it’s best to encapsulate game logic in the object to which it relates - so Object A should be responsible for handling its own collision responses)