Collision detection without code pasted onto objects

Hey guys,

Is there a way to check if an object has collided with another without pasting the OnCollisionEnter onto one of those objects?

I do not want code everywhere all over objects, I’m a pro developer and that is the way you code when you’re 15 and just starting out.

I’m hoping for one of these two ways:

  1. Overriding the event method from my main controller script (the only script)

GameObject.OnCollisionEnter = function()
//do something

  1. Checking for a property value directly.

if (GameObject.collider.hasCollisionThisFrame)
//get object collided with and do something

I’m really hoping there is a way to do this. Basically I just want to have all my code in one script file and not all over the place.


I’ll give that a read. Thanks.

You’re right that having all your code in one place isn’t exactly a brilliant way to code but I can’t see any ways of having a proper class structure either.

I’ve worked with component based development before (with Actionscript and Flash) and it leads to totally unwieldy, poor performing code and any new dev coming onto a project has no idea where to find anything because the code is strewn all over the place.

I fully appreciate that Unity is supposed to be a tool that enables non devs to create games but there should at least be the option for pros to develop in regular ways.

So I’m assuming there is no way then?