From the course: Advanced Unity 2D: Platformer Player Movement

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Abstracting axis input

Abstracting axis input - Unity Tutorial

From the course: Advanced Unity 2D: Platformer Player Movement

Start my 1-month free trial

Abstracting axis input

- So now that we're keeping track of an axis state, we need a way to actually convert this to a button press and get a value out to determine whether the button is being pressed or not. In order to do this, we're gonna need to test the value that we're getting back from the axis itself, inside of our axis state. Let's go back into our scripts and open the InputManager. We're gonna create a new enum, we'll make this public enum called Condition. And just like we would do normal conditionals in coding, we're gonna keep track of the value of greater than or less than as it relates to the off value of the InputAxisState. Let's add these two properties to our enum. Now, inside of the InputAxisState class, let's add a new property to keep track of what Condition we should be testing for. Now that we have the Condition, we actually need a way of calculating the value. One way that we can do this is by creating a getter for the value property. Getters and setters allow us to do additional…

Contents