No Overload for method "attack' takes 1 arguements

Hi, im confused on what i’ve done wrong here

using System;
using RPG.Combat;
using RPG.Movement;
using UnityEngine;

namespace RPG.Control
{
    public class PlayerController : MonoBehaviour
    {
        private void Update()
        {
            InteractWithCombat();
            InteractWithMovement();
        }

        private void InteractWithCombat()
        {
           RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
           foreach (RaycastHit hit in hits)
           {
             CombatTarget target = hit.transform.GetComponent<CombatTarget>();
             if (target == null) continue;
             if (Input.GetMouseButtonDown(0))
             {
                 GetComponent<Fighter>().Attack(target);
             }
           }
                      

           }
        private void InteractWithMovement()
        {
            if (Input.GetMouseButton(0))
            {
                MoveToCursor();
            }
        }

        private void MoveToCursor()
        {
            RaycastHit hit;
            bool hashit = Physics.Raycast(GetMouseRay(), out hit);
            if (hashit)
            {
                GetComponent<Mover>().MoveTo(hit.point);
            }
        }

        private static Ray GetMouseRay()
        {
            return Camera.main.ScreenPointToRay(Input.mousePosition);
        }
    }
}

For future posts, format the code by typing three ` on a line by itself before pasting in the code. I’ve formatted your post for you to make it more readable to us old code fogeys. :slight_smile:
For example:
```
Some code
```
becomes

Some code

The error message is telling you that the signature of Fighter.Attack() does not match what you’re calling. Paste in your Fighter’s Attack method and we’ll take a look.

using UnityEngine;

namespace RPG.Combat
{
    public class Fighter : MonoBehaviour
    {
        public void Attack(CombatTarget target)
        {
            print("Take that you short, squat peasent");
        }
    }
}

this is all the video has to add to it

Is it just Visual Studio Code that is reporting the error, or is Unity also throwing the same error?

that’s the weird part, only unity has an error, VS code is fine with it

Wait, never mind, the problem fixed it’s self

Sometimes weird things like this happen in Unity… usually restarting or deleting the Library folder fixes it.

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

Privacy & Terms