#Need some help about input on unity

1 messages · Page 1 of 1 (latest)

dawn zephyr
#

I'm a French student and I'm trying to use unity for my school project. The goal is to make a VR drone flight simulator. We are 4 and my part is about using a radio command.

I'm trying to use the Input System package but when I'm trying to move my square to test my code I got an error message :
"InvalidOperationException while executing 'performed' callbacks of 'Gameplay/MoveRight[/Keyboard/d]'"

For the moment I just want to try to move my square to the right by using D. I think the problem is from my code I just followed a video that explains how to use the input package but my lack of experience in unity and C# don't allow me to get rid of my problem I tried to search on some Unity forum but nothing helped.

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

public class Deplacement : MonoBehaviour
{
        PlayerControls controls;

        Vector2 move;

    void Awake(){
        controls = new PlayerControls();
        controls.Gameplay.Grow.performed += ctx => Grow();
        controls.Gameplay.MoveRight.performed += ctx => move = ctx.ReadValue<Vector2>(); 
        controls.Gameplay.MoveRight.canceled += ctx => move = Vector2.zero; 

    }

    void Grow(){
        transform.localScale *= 1.1f;
    }

    void Update(){
        Vector2 m = new Vector2(-move.x, move.y) * Time.deltaTime;
        transform.Translate(m, Space.World);
    }

    void OnEnable(){
        controls.Gameplay.Enable();
    }

    void OnDisable(){
        controls.Gameplay.Disable();
    }

}

Even if the video is well-made, I still can't understand some details about his code.

Thanks in advance catto

(BTW if someone know how to fix the missing R in the search bar from the input action menu, I already change it but it keep come back)

spiral lily