Can't get Input.GetAxis( )

When I hit the play button, and no matter if I hit the left、right、up、down, or AWSD buttons, I just can’t get the input value, it always prints 0 to the console…

Below is my player movement script

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

public class PlayerController : MonoBehaviour
    [SerializeField] float movementSpeed = 10;
    [SerializeField] float xAxisRange = 5; //玩家可以移動的X軸範圍
    [SerializeField] float yAxisRange = 5; //玩家可以移動的Y軸範圍

    // Update is called once per frame
    void Update()
        float horizontalThrow = Input.GetAxis("Horizontal");

        float verticalThrow = Input.GetAxis("Vertical");


I’m sure I have implemented the script into the Player object

Could anyone help me figure out what I doing wrong?

My Unity version: 2022.3.7f1

Do you perhaps have the setting set to use the new input system? You can check in the project settings under Player. Find this entry

Thanks for your answer, I’ve checked my player setting options, and the Active Input Handing is using “Input Manager ( old )”
still not working…

--------2023/9/4 update----------
I found when I hit play, and focus on the Game viewport, I can get the Input value in the console.
If I focus on the Console Area, it would just print nothing but 0.
I think toggle Play Maximized in the Game viewport will help avoid this issue

Good find. It’s because the window doesn’t have the focus, so it doesn’t receive the keyboard input.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms