Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Says InputManager has no definition to OnFoot and I fallowed the tutorial exactly as it says

Discussion in 'Getting Started' started by Notit44, May 3, 2024.

  1. Notit44

    Notit44

    Joined:
    Mar 22, 2024
    Posts:
    4
    Assets\Script\Player\PlayerInteract.cs(36,34): error CS1061: 'InputManager' does not contain a definition for 'OnFoot' and no accessible extension method 'OnFoot' accepting a first argument of type 'InputManager' could be found (are you missing a using directive or an assembly reference?)

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerInteract : MonoBehaviour
    {
    private Camera cam;
    [SerializeField]
    private float distance = 3f;
    [SerializeField]
    private LayerMask mask;
    private PlayerUI playerUI;
    private InputManager inputManager;
    // Start is called before the first frame update
    void Start()
    {
    cam = GetComponent<PlayerLook>().cam;
    playerUI = GetComponent<PlayerUI>();
    inputManager = GetComponent<InputManager>();
    }

    // Update is called once per frame
    void Update()
    {
    playerUI.UpdateText(string.Empty);
    //create a ray at the center of the camera, shooting outwards.
    Ray ray = new Ray(cam.transform.position, cam.transform.forward);
    Debug.DrawRay(ray.origin, ray.direction * distance);
    RaycastHit hitInfo; // variable to store our collision information.
    if (Physics.Raycast(ray, out hitInfo, distance, mask))
    {
    if (hitInfo.collider.GetComponent<Interactable>() != null)
    {
    Interactable interactable = hitInfo.collider.GetComponent<Interactable>();
    playerUI.UpdateText(interactable.promptMessage);
    if (inputManager.OnFoot.Interacted.triggered)
    {
    interactable.BaseInteract();
    }
    }
    }
    }
    }
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,254
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978
    or its inputManager, not InputManager...

    (I know ive seen this question more than once so the answer is, it is a typo)
     
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,254
    If that was the case, we'd be getting an error saying InputManager isn't defined, not OnFoot.
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978
    No, see the variables the CLASS is called InputManager, the variable is inputManager..
     
  6. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,254
    Please actually look at the code.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerInteract : MonoBehaviour
    7. {
    8.     private Camera cam;
    9.     [SerializeField]
    10.     private float distance = 3f;
    11.     [SerializeField]
    12.     private LayerMask mask;
    13.     private PlayerUI playerUI;
    14.     private InputManager inputManager;
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         cam = GetComponent<PlayerLook>().cam;
    19.         playerUI = GetComponent<PlayerUI>();
    20.         inputManager = GetComponent<InputManager>();
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.         playerUI.UpdateText(string.Empty);
    27.         //create a ray at the center of the camera, shooting outwards.
    28.         Ray ray = new Ray(cam.transform.position, cam.transform.forward);
    29.         Debug.DrawRay(ray.origin, ray.direction * distance);
    30.         RaycastHit hitInfo; // variable to store our collision information.
    31.         if (Physics.Raycast(ray, out hitInfo, distance, mask))
    32.         {
    33.             if (hitInfo.collider.GetComponent<Interactable>() != null)
    34.             {
    35.                 Interactable interactable = hitInfo.collider.GetComponent<Interactable>();
    36.                 playerUI.UpdateText(interactable.promptMessage);
    37.                 if (inputManager.OnFoot.Interacted.triggered)
    38.                 {
    39.                     interactable.BaseInteract();
    40.                 }
    41.             }
    42.         }
    43.     }
    44. }
    45.  
    The variable "inputManager" is of the class "InputManager." "inputManager" is assigned via the GetComponent call in Start(). "inputManager.OnFoot" is called in Update.

    The issue is that something is wrong in the InputManager class.
     
  7. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978

    I did, but the fact its hard to read because people cant be bothered with code tags doesnt help.. so yes, you're right, it is a little I but in the original it looks more like a capital
     
  8. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,254
    It wouldn't matter regardless because the error message still would have been different. If what you were saying was the case, the error would have been "can not convert from method group to object."
     
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,448
    We need to see the InputManager class since that's where it's supposedly missing. A link to the tutorial would help too.
     
  10. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,448
  12. Notit44

    Notit44

    Joined:
    Mar 22, 2024
    Posts:
    4
    I have already tried the onFoot instead of OnFoot and I got an error
    error CS0122: 'InputManager.onFoot' is inaccessible due to its protection level
     
  13. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978
    did you read ALL of the linked post? about private and public?
     
  14. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,254
     
  15. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,448
    Is it set to
    protected
    or
    private
    ? Because if it is you can't access it from outside the class. You need to set it to
    public
    for it to be accessible.
     
  16. Notit44

    Notit44

    Joined:
    Mar 22, 2024
    Posts:
    4
    Here is the InputManager code and the tutorial I watched

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;

    public class InputManager : MonoBehaviour
    {
    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;

    private PlayerMotor motor;
    private PlayerLook look;
    private PlayerInteract interact;
    // Start is called before the first frame update
    void Awake()
    {
    playerInput = new PlayerInput();
    onFoot = playerInput.OnFoot;

    motor = GetComponent<PlayerMotor>();
    look = GetComponent<PlayerLook>();

    onFoot.Jump.performed += ctx => motor.Jump();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
    //tell the playermotortomove using the value from our movement action.
    motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
    }
    private void LateUpdate()
    {
    look.ProcessLook(onFoot.Look.ReadValue<Vector2>());
    }
    private void OnEnable()
    {
    onFoot.Enable();
    }
    private void OnDisable()
    {
    onFoot.Disable();
    }
    }
     
  17. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,978
    As we both said (and the compiler) , you cant access that its private. As the reddit thread detailed, you need to change that to public..
     
  18. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,448
    The first comment on the video states what's wrong: he left out some footage showing him correcting mistakes he had made in the code. The correction in this case is like we said: change
    OnFoot
    's permission from
    private
    to
    public
    .

    upload_2024-5-7_19-31-6.png

    Slight rant: I hate tutorials where the author presents the code by typing it up in the video as it enables mistakes like this. It's not like them typing it is somehow going to make it easier to understand. Just copy and paste tested code, or show the entire class in its finished state.
     
    Last edited: May 8, 2024