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.

Reading from the input state class

Reading from the input state class - Unity Tutorial

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

Start my 1-month free trial

Reading from the input state class

- So now that we have our input manager talking to the input state, the only thing left is for us to map this over to the simple movement script we created earlier. But before we do this, we actually need to get the value out of the input state for the keys that are being pressed. Let's open up our input state class. Inside of this, we'll create a new public method called get button value, that returns a bullion. Here you see we're passing in our key enum, and we'll need to make sure that the value actually exists on the button states before we try to get it. Next, we'll return that value. If there is no value, we'll simply return faults. Next, let's take a look at our simple movement script. Here we're going to need to add two new properties. One that manages the actual input keys that we're mapping to, and the other the input state itself. Let's create a public property. This will be an array of buttons, and we'll call this input. Next, we'll make a private property for the input…

Contents