Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question InputAction broken?

Discussion in 'Scripting' started by Elderdevduo, Jan 30, 2023.

  1. Elderdevduo

    Elderdevduo

    Joined:
    Dec 15, 2022
    Posts:
    3
    The following code provides this error : Assets\Game\Scripts\Move2d.cs(11,22): error CS0246: The type or namespace name 'InputAction' could not be found (are you missing a using directive or an assembly reference?)

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

    public class Move2d : MonoBehaviour
    {
    private Rigidbody2D _rigidbody2D;
    public float m_speed = 1.0f;
    private Vector2 _userinput;
    public void Move(InputAction.CallbackContext context)
    {
    _userinput = context.ReadValue<Vector2>();
    }

    void Start()
    {
    _rigidbody2D = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
    _rigidbody2D.MovePosition(_rigidbody2D.position + _userinput * Time.fixedDeltaTime * m_speed);
    }
    }


    I haven't any idea why I can't use InputAction , I even tried the all powerful ChatGPT but got nowhere.


     
  2. DavidTeo

    DavidTeo

    Unity Technologies

    Joined:
    Apr 1, 2021
    Posts:
    69
    Hello, just to check with you if you have already installed the Input System package from the Package Manager (which can be accessed from the top menu Window -> Package Manger)

    Otherwise, it will be faster to get relevant replies and information in the Input System forum section
     
    Elderdevduo likes this.
  3. Elderdevduo

    Elderdevduo

    Joined:
    Dec 15, 2022
    Posts:
    3
    Thank you sir i am a noob who didn't install the package!
     
    DavidTeo likes this.