The referenced script on the Behavior (Game Object 'Player') is missing!

using UnityEngine;

public class PlayerCollision : MonoBehaviour {

    void OnCollisionEnter(Collision collisionInfo)
    {
        if (collisionInfo.gameObject.tag == "Cube")
        {
            Debug.Log("yay");
        }
    }

}

I can’t figure out why this script isn’t working! Please help

What does it mean it “isn’t working” and what would be the “working”?

  • do you have errors in the console? if yes, have you tried to fix them?
  • if no error, have you tried to put debug.log outside of the “if” section but inside the method? → if it does not show then you have something wrong with the collision, missing collider or rigidbody
  • if it shows than are you sure you have this tag and the game object you are colliding with has it?

Sorry for the vagueness, when I say it isn’t working, it isn’t printing “yay” in the console when my player hits a “Cube”. Instead it displays “The referenced script on the Behavior is missing” and “The referenced script on the Behavior (Game Object ‘Player’) is missing”. I have searched through forums to help solve this problem but nothing has worked. It also has the same problem without the if statement. I am also sure that “Cube” is the correct tag and has and RB and collider.