GetAxis

If you're looking for a function that will trigger continuously without any breaks between firing, you want to use GetAxis() rather than GetButton(). GetButton() is good for buttons you want to hold down but want a slight pause between events firing (think holding down a fire button, and the gun shoots bullets with breaks in between them). GetAxis() works better for events involving movement because of this continuous frame-rate independent execution.

GetAxis() works a bit differently, as it returns a float value rather than a Boolean, such as GetButton(). It is also best suited within an Update() function. So, for example, you can check whether the horizontal movement is occurring, as follows:

void Update () { float horizontalValue= ...

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.