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().cam;
playerUI = GetComponent();
inputManager = GetComponent();
}
// 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() != null)
{
Interactable interactable = hitInfo.collider.GetComponent();
playerUI.UpdateText(interactable.promptMessage);
if (inputManager.OnFoot.Interacted.triggered)
{
interactable.BaseInteract();
}
}
}
}
}
Do you have the case right? Are you sure you didn’t name OnFoot “onFoot” or something else? We can’t diagnose this without seeing your InputManager code. Also, use code tags.
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();
}
}
}
}
}
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.
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
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.”
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();
look = GetComponent();
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());
}
private void LateUpdate()
{
look.ProcessLook(onFoot.Look.ReadValue());
}
private void OnEnable()
{
onFoot.Enable();
}
private void OnDisable()
{
onFoot.Disable();
}
}
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.
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.