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.

Building an input state class

Building an input state class - Unity Tutorial

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

Start my 1-month free trial

Building an input state class

- So now that our InputManager is able to take inputs from Unity and convert them into buttons that our game can use, we're going to need a place to store whether the button has been pressed or released. To get started, let's go back into our Projects folder and in scripts we're going to create a new C# script called inputState. Open it up in MonoDevelop and we'll begin adding the code. Now just like we did with our InputManager, we're going to need a special class in order to keep track of the actual button state itself. Above our inputState, let's create this new class. We'll make is a public class called buttonState. Now since we're not going to be changing this in the IDE, we don't need to worry about serializing the object. All we need to do is have a boolean that keeps track or whether the button is pressed or not. We'll make this a public boolean called value. Next, in our inputState we're going to need to keep a collection of all the button states in our game. In order to do…

Contents