RPG Core Combat Swappable Control Systems

Having an issue at the change at 3:37 in the video.
Sam changes the inline on PlayerController from

this

        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent<CombatTarget>();

                if (!GetComponent<Fighter>().CanAttack(target))
                {
                    continue;
                }
                if(Input.GetMouseButtonDown(0))
                {
                    GetComponent<Fighter>().Attack(target);
                }
                return true;
            }
            return false;
        }

To this

        private bool InteractWithCombat()
        {
            RaycastHit[] hits = Physics.RaycastAll(GetMouseRay());
            foreach (RaycastHit hit in hits)
            {
                CombatTarget target = hit.transform.GetComponent<CombatTarget>();
                if (target == null) continue;

                if (!GetComponent<Fighter>().CanAttack(target.gameObject))
                {
                    continue;
                }
                if(Input.GetMouseButtonDown(0))
                {
                    GetComponent<Fighter>().Attack(target.gameObject);
                }
                return true;
            }
            return false;
        }

this issue I’m getting is that the

GetComponent<Fighter>().Attack(target.gameObject);

says that it cant get target.gameObject

unity error
Assets\Scripts\Control\PlayerController.cs(31,52): error CS1503: Argument 1: cannot convert from ‘UnityEngine.GameObject’ to ‘RPG.Combat.CombatTarget’

i don’t know how to fix it and I have looked at the repo but i don’t know how to get the code from it.

any help would be great
Thanks!

Solution: I didn’t change the Fighter Script

Public void Attack(Combat target combatTarget)

should have been changed to

Public void Attack(GameObject combatTarget)

Good job on solving the problem, and thanks for sharing your solution. :slight_smile:


See also:

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