Cannot cancel attack in the game

Fighter.cs

using UnityEngine;
using RPG.Movement;
using RPG.Core;

namespace RPG.Combat
{
    public class Fighter : MonoBehaviour, IAction
    {
        [SerializeField] float weaponRange = 2f;

        Transform target;
        private void Update()
        {
            if (target == null) return;
            if (!GetIsInRange())
            {
                GetComponent<Mover>().MoveTo(target.position);
            }
            else
            {
                GetComponent<Mover>().Cancel();
            }
        }

        private bool GetIsInRange()
        {
            return Vector3.Distance(transform.position, target.position) < weaponRange;
        }
        public void Attack(CombatTarget combatTarget)
        {
            GetComponent<ActionScheduler>().StartAction(this);
            target = combatTarget.transform;
        }
        public void Cancel()
        {
            target = null;
        }
    }
}
namespace RPG.Core
{

    
    public interface IAction
    {
        void Cancel();
    }

}
using UnityEngine;

namespace RPG.Core
{
    public class ActionScheduler : MonoBehaviour
    {
    //אנו קוראים לחוזה שלנו
        IAction currentAction;

        public void StartAction(IAction action)
        {
            if (currentAction == action) return;
            if (currentAction != null)
            {
                currentAction.Cancel();
            }
            currentAction = action;
        }
    }
}

I don’t know why but my Char wont cancel the attack

I do not know what happened but after I restarted it it decided to work properly

Turns out I can not write comments so it does not work properly, does anyone have an idea how to fix this (so there was a glitch)

I formatted the scripts for you.

Just confirming that this is working properly. All good?

It currently works properly but it does not allow me to take notes. Once I write comments, the “cancel attack” does not work.

It’s possible that the Hebrew font is confusing the compiler.

Privacy & Terms