- Home /
Input.GetAxis always return 0
I have the following piece of code that am running on my Mac Pro with trail version of Unity 4. I am quite new to unity and game programming and maybe am missing something very obvious so any help is greatly appreciated.
function Update () {
Debug.Log("X=" + Input.GetAxis("Horizontal") + " Y=" + Input.GetAxis("Vertical"));
}
Both horizontal and vertical axis always return zero. Below, I have an image of my input manager.
Thanks!
$$anonymous$$ind of a dumb question for me to ask, but just to make sure, are you actually pressing the keys you have set up for Horizontal? And are you pressing them after you've already hit the Play button? Also, is the script attached to your character?
Yes, I am pressing the left & the right arrow after I hit the play button. The script is attached to my main camera. Thanks
Answer by TonyLi · Oct 24, 2013 at 02:07 AM
Sorry for reviving an old question, but I thought I'd share the answer for a similar problem I just encountered.
I imported Azuline Studios' Realistic FPS Prefab into a project, and it added tags, layers, and who knows what else. But, pertinent to this question, it also added two additional InputManager Axes named "Vertical" and "Horizontal" that weren't assigned any keys. These were in addition to the existing "Vertical" and "Horizontal" that the project had by default.
These caused Input.GetAxis("Vertical") to always return zero, which broke my project until I removed the duplicates.
I had some $$anonymous$$aterial/Prefabs applied to my Player who was using Input.GetAxis("Horizontal") and i dont know what it basically done, but after deleting them, it started working. I hope your comment is reason behind that.
had the same issue with a different package - it changed the Axis tags for horizontal and vertical movement...
lesson learned: check your Input Manager (in Project Settings) and ensure the Axis tags you're referencing actually exist
Your answer
Follow this Question
Related Questions
Touch to turn wheelcolllider.steerAngle with limits 1 Answer
Making a Paddle Move Vertically? 1 Answer
Input.GetAxisRaw with delete and shift 0 Answers
GameController Unity wrong Axis-Values 0 Answers
How Do I Snap Input Between 1, 0, and -1 0 Answers