So the error seems to be on Line 16?
I Googled NullReferenceExceptions and they were explained as when a variable is not assigned properly, or to null. But in this case I see the bool IsInRange is assigned properly?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
namespace RPG.Combat
{
public class Fighter : MonoBehaviour
{
[SerializeField] float weaponRange = 2f;
Transform target;
private void Update() {
bool isInRange = Vector3.Distance(transform.position, target.position) < weaponRange;
if (target != null && !isInRange)
{
GetComponent<Mover>().MoveTo(target.position);
}
else
{
GetComponent<Mover>().Stop();
}
}
public void Attack(CombatTarget combatTarget)
{
target = combatTarget.transform;
}
}
}