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.

Saving direction state

Saving direction state - Unity Tutorial

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

Start my 1-month free trial

Saving direction state

- So now that we know which direction the player is supposed to be facing, it's time for us to hook this up. Now an important thing that we're gonna need to keep in mind is that behaviors are gonna be self-contained. So in the case of the Face Direction behavior it's not necessarily gonna know anything else about Walk or Jump or any of the other behaviors we'll implement later in this course. Now in order for one behavior to communicate to another behavior, we're gonna need a bridge. And the input state class will act as that bridge. Every behavior will point to the input state and read state value. So when it comes to something important like direction we're gonna wanna make sure that we have the direction value accessible through any of the other classes that we have. Now in order to do this, we're gonna take advantage of the fact that the face behavior can talk back to the input state, and the input state will relay that message to other behaviors that are looking at its values…

Contents