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;
}
}