Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Input Manager Error

Discussion in 'Input System' started by De4thwish, Feb 9, 2024.

  1. De4thwish

    De4thwish

    Joined:
    Jan 12, 2023
    Posts:
    2
    Im trying to make a basic interact function so the player can pick up weapons and interact with doors, but for some reason it gives me an error that says:

    "
    Severity Code Description Project File Line Suppression State
    Error CS1061 'object' does not contain a definition for 'Interact' and no accessible extension method 'Interact' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\dylan.walden\Heavy Metal\Assets\Scripts\Player\Player Interact.cs 37 Active "

    Here is the code. The error is on the line that says "if (input.OnFoot.Interact.triggered)"


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

    public class PlayerInteract : MonoBehaviour
    {
    private Camera cam;
    [SerializeField]
    public float distance = 3f;
    [SerializeField]
    private LayerMask mask;
    private PlayerUI ui;
    private InputManager input;


    void Start()
    {
    cam = GetComponent<MouseLook>().cam;
    ui = GetComponent<PlayerUI>();
    input = GetComponent<InputManager>();

    }

    void Update()
    {
    ui.UpdateText(string.Empty);
    Ray ray = new Ray(cam.transform.position, cam.transform.forward);
    Debug.DrawRay(ray.origin, ray.direction * distance);
    RaycastHit hitInfo; //stores collision data for ray
    if(Physics.Raycast(ray, out hitInfo, distance, mask))
    {
    if (hitInfo.collider.GetComponent<InteractBase>() != null)
    {
    InteractBase interact = hitInfo.collider.GetComponent<InteractBase>();
    ui.UpdateText(interact.promptMessage);
    if (input.OnFoot.Interact.triggered)
    {

    }
    //only use the line below to see if things are working right
    //Debug.Log(hitInfo.collider.GetComponent<InteractBase>().promptMessage);
    }
    }
    }
    }


    Does anyone know what I can do to fix this? I have the action set in the input manager and it has binds and everything, so that isn't the issue. I just don't know what to do.
     
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,696
    what does your input system setup look like? m (and please learn to use the code tags)
     
  3. De4thwish

    De4thwish

    Joined:
    Jan 12, 2023
    Posts:
    2
    Alright, I will. And here is the input system
     

    Attached Files:

  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,796
    Make sure you have generated a C# class for your action map, and also make sure you're using the right class name. your action map seems to be called "PlayerInput" not "InputManager".