Help me error

Continuing the discussion from Error in run unity:
Assets\Scripts\Control\PlayerController.cs(19,52): error CS0103: The name ‘GetMouseRay’ does not exist in the current context
this is all the code

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()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            bool hasHit = Physics.Raycast(ray, out hit);
            if (hasHit)
            {
                GetComponent<Mover>().MoveTo(hit.point);
            }
        }
    }
}

You don’t have a GetMouseRay() function. You need to create it. Sam creates this function in the ‘Raycasting For Components’ lecture.

@bixarrio has it.

As a hint, GetMouseRay() returns the same result as we assign the Ray ray in MoveToCursor()

thanks i was fix it this error

i was fixed thanks

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

Privacy & Terms