Hi, I’m having trouble finding the cause of this null reference exception:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;
namespace RPG.Combat
{
public class Fighter : MonoBehaviour
{
[SerializeField]
float weaponRange = 2f;
private Transform target;
private void Update()
{
bool isInRange = Vector3.Distance(target.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;
}
public void Cancel()
{
target = null;
}
}
}