Pls Help My collision code wont work

using UnityEngine;

public class PlayerCollision : MonoBehaviour
{

    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.collider.tag == "Enemy")
        {
            Debug.Log("WE Hit balls");
        }

    }

}

Basically i just get these warnings
The referenced script (Collision) on this Behaviour is missing!
and
The referenced script on this Behaviour (Game Object ‘player’) is missing!

You never have to post for this error.

Why?

Because posting on the forum is NOT one of the only three steps that will fix this error:

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null
  • Identify why it is null
  • Fix that

I have a feeling the names of your script files don’t match the names of the classes inside them.

1 Like

yes that’s it 100%

1- Rename you script in the editor
2- rename your class
3- save and test

Ok thanks guys