WHen I pasted the void Hit method, I broke the code again

Sorry for the many questions I feel I am getting my groove!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Movement;

namespace RPG.Combat 
{
    public class Fighter : MonoBehaviour
    {
        [SerializeField] float weaponRange = 2f;
        [SerializeField] float timeBetweenAttacks = 1f;
        [SerializeField] float weaponDamage = 5f;


    Transform target;
        float timeSinceLastAttack = 0;

    private void Update()
        {
            timeSinceLastAttack += Time.deltaTime;


            bool isInRange = GetIsInRange();
            if (target != null && isInRange)
            {
                GetComponent<Mover>().MoveTo(target.position);
            }
            else
            {
                GetComponent<Mover>().Stop();
                AttackBehaviour();
            }
        }

        private void AttackBehaviour()
        {
            if (timeSinceLastAttack > timeBetweenAttacks)

            {
                GetComponent<Animator>().SetTrigger("attack");
                timeSinceLastAttack = 0;
                
            }
        }

        void (Hit)
            {
            Health healthComponent = target.GetComponent<Health>();
            healthComponent.TakeDamage(weaponDamage);
            }

    private bool GetIsInRange()
        {
            return Vector3.Distance(transform.position, target.position) < weaponRange;
        }

        public class Fighter : MonoBehaviour
        {
            public void Attack(CombatTarget combatTarget)
            {
                target = combatTarget.transform;
            }

            public void Cancel()
            {
                target = null;
            }

       
    }
}

It's probably another misplaced } but I can't for the life of me see where it is.

Always specify what the error was when asking for help on errors. I broke the code doesn’t generally give me enough information.

If you click on the error message in the console, it will generally tell you the line in which the error occured (or at least where things stopped making sense to the compiler).

In this case, we have a public class Fighter : Monobehaviour statement along with an opening bracket which is causing your code to break.
Just before public void Attack(CombatTarget combatTarget) remove the class declaration and the opening { right after it.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms