Can't get Enemy info on mouse over.

Hi, I am trying to get a function in which I am hovering my mouse over the enemy and it shows what the enemy is. However, this is what I received in the error log, instead of printing “This is an enemy.” in the log.

NullReferenceException: Object reference not set to an instance of an object
Mob.OnMouseOver () (at Assets/Scripts/Mob.cs:43)

This is the abridged code below.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mob : MonoBehaviour {

    void OnMouseOver()
    {
        Debug.Log ("This is an enemy.");
        player.GetComponent<Fighter> ().opponent = this.gameObject;
    }
}

check if your player variable is not null.

make sure your player variable is not null.

I assume the double post is an accident.

Either ‘player’ is null or ‘player’ does not have the component ‘Fighter’. Make sure both exist.