NullReferenceException: Object reference not set to an instance of an object guy.OnCollisionEnter2D (UnityEngine.Collision2D col) (at Assets/guy.cs:15)

I keep getting this error. I am trying to aces the pause function in a separate script play.

public class guy : MonoBehaviour {
	public play stop;

	void OnCollisionEnter2D (Collision2D  col){

		stop.pause();
		
	}


}

You never assign stop a reference.

ie. You need to at a minimum do something like.

play stop = new play();

but you are probably after (assuming that you have a play scrip assigned to this same object)

public Start()
{
    stop = this.gameObject.GetComponenet<play>();
}

void OnCollisionEnter2D (Collision2D col)
{    
    if (stop != null)
    { 
        stop.pause();
    }     
}