Error CS7036

When I add the parameters (CombatTarget combatTarget) to Attack() I am given an error in Unity saying no argument given that corresponds to the required formal parameter.

I can confirm the Combat Target script is attached to my enemy. My Combat Target script looks like this:

using UnityEngine;

namespace RPG.Combat

{
    public class CombatTarget : MonoBehaviour
    {

    }
}

My fighter script looks like this:

using UnityEngine;
using RPG.Movement;

namespace RPG.Combat
{
    public class Fighter : MonoBehaviour
    {
        Transform target; 

        void Update()
        {
            if (target != null)
            {
                GetComponent<Mover>().MoveTo(target.position);
            }
        }
        public void Attack(CombatTarget combatTarget)
        {
            target = combatTarget.transform;
            print ("Take that, corporate scum!");
        }

    }
}

Have I missed something?

SOLVED! Issue was actually in my Player Controller script - I forgot to add (target) to:

GetComponent().Attack(target);

1 Like

Iā€™m glad you were able to sort that out. Sometimes the error message can lead us to the wrong script.

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

Privacy & Terms