using unityengine.input system code example

Example 1: unity controller input

float moveSpeed = 10;
//Define the speed at which the object moves.

float horizontalInput = Input.GetAxis("Horizontal");
//Get the value of the Horizontal input axis.

float verticalInput = Input.GetAxis("Vertical");
//Get the value of the Vertical input axis.

transform.Translate(new Vector3(horizontalInput, 0, verticalInput) * moveSpeed * Time.deltaTime);
//Move the object to XYZ coordinates defined as horizontalInput, 0, and verticalInput respectively.

Example 2: unity input system not working

//add this somewhere in your script
//PlayerControls is the Input action script

PlayerControls controls;

private void Awake()
{
	controls = new PlayerControls();
}

private void OnEnable()
{
	if (usingController)
	{
		controls.Gameplay.Enable();
	}
}

private void OnDisable()
{
	if (usingController)
	{
		controls.Gameplay.Disable();
	}
}

Tags:

Cpp Example