Game Object Error

Please Help :slight_smile:
I’m getting an " Object reference not set to an instance of an object" error and I can’t figure out why :0

Code as follows:

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;
            print("Take That!!");
        }
    }
}

Its on the first line of my update method where i initiate the bool isInRange

Privacy & Terms