So this is not my first time using this function, I’ve used it 100s of times with ease. But it’s been a couple months since I’ve worked with Unity and am starting a new project now. First time I go to use it, it doesn’t work.
I am not getting any error. It just simply isn’t working. My code:
function Start ()
{
}
function Update ()
{
}
function OnCollisionEnter2D (colsn : Collision2D)
{
print ("It is working!!"); // This does not trigger PERIOD
}
I made the above script as BASIC as possible to ensure nothing was interfering and it still refuses to work. Nothing happens at all.
I drag it through objects with colliders on them making sure it is passing through the collider.
The object with the above code attached has a Box Collider 2D on it that is NOT a trigger. None of the other colliders are triggers.
What is going wrong?
PS: Using Unity 5.6.1f1
EDIT: I have tried having the same script attached to other objects involved in the collision and that does not change things. For some reason, collisions are not being registered at all.
EDIT II: I have also tried the other collision types (OnExit and OnStay) and have tried a variety of colliders. Nothing fixes it.
Any help would be greatly appreciated!
SOLUTION!
I forgot to add a Rigidbody2D to one of the objects involved in the collision. All objects involved in a collision must have a Rigidbody attached!
- Chris