Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    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:
    71
    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
     
    MattThomSA and Elderdevduo like 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.