I am building a RPG game in Unity3d, and I came across this error "NullReferenceException: Object reference not set to an instance of an object" and I really don't get what is wrong.
My code is this:
using UnityEngine;
using RPG.Move;
namespace RPG.Lupta
{
public class Luptator : MonoBehaviour
{
[SerializeField] float distantaArma =2f;
Transform tinta;
private void Update()
{
bool isInRange = GetIsInRange();
if (tinta != null & !GetIsInRange())
{
GetComponent<Mover>().MutareCatre(tinta.position);
}
else
{
GetComponent<Mover>().Stop();
}
}
private bool GetIsInRange()
{
return Vector3.Distance(transform.position, tinta.position) < distantaArma;
}
public void Atac(TintaLupta tintaLupta)
{
tinta = tintaLupta.transform;
}
public void Cancel ()
{
tinta = null;
}
}
}
It says that the error is on line 14 and 28, which are these :
Line 28: return Vector3.Distance(transform.position, tinta.position) < distantaArma;
Line 14: bool isInRange = GetIsInRange();
Does anyone know what the problem might be?