‫All right.
‫So let's go ahead and see how we can start the game.
‫So far, we simply started by starting the game in Unity, but we want to start the game within the
‫game so the player can start the game by pressing the space key.
‫So let's do that by creating a new script.
‫So let's go to scripts, create C-sharp script, and I'm going to call it Game Manager.
‫That one is going to control our game states.
‫So let's create a game style game manager game object in here as well.
‫So Game Manager and let's drag that script right into our game manager.
‫I'm going to reset the position of the game manager just so that it's cleaned and into at the zero position.
‫All right.
‫So let's have a look at our game manager.
‫As you can see, it already gets a different kind of icon in Unity because the game manager is a very
‫special script, which, as I said, will take care of our game states.
‫So the game manager will be very simple.
‫We won't need to start or update method for now.
‫We will just need a boolean which is the state whether our game is started or not.
‫So public bool game started and I'm going to create a method public void start game and I'm going to
‫make it public so that I can access it or I can use it from outside of the game manager itself.
‫So I'm from another script and in here the only thing I do is I set game started to true whenever the
‫start game method is called, the only thing that happens our game started.
‫Boolean is set to true.
‫So now in our controller what we need is we need to access our game manager because what we want to
‫do is whenever the player press the space key, the fixed update method should, should recognize that
‫and should start the game.
‫So let's go ahead and do that.
‫So let's create a private game manager and let's call it game manager.
‫So now in the Awake method I need to initialize it, otherwise our game manager will be null and we'll
‫get an error.
‫So let's solve that find object of type and let's call that one game manager because we're just searching
‫for the object that has or that is of type game manager and we only have one and that's our game manager,
‫right?
‫So we want to have that one and it contains a script and we want to access it.
‫So what we can do now is we can check if the game has not started.
‫So game manager, not game manager, that game started, which means the boolean game started is false.
‫Then return.
‫So don't do anything.
‫So let's save that script and let's go back to Unity.
‫Check it out.
‫Let's run our game.
‫And we can see the player is not moving.
‫The game has not started.
‫The animation, however, is still there.
‫So our player is still animating and we should solve that because that's not a nice state.
‫We have the player here and he's fake running.
‫That's not fun, so we need to change it.
‫Actually, it's funny, but we need to change that.
‫So let's create a new state because we have only the two states here running and falling so we can either
‫run, which is great, or we can fall, which is not so great, but we can also just be idle.
‫So let's create an empty state and let's call that one idle and you guess it, right?
‫There is a motion in our assets for that which is called idle.
‫So we can just use that motion, which is an animation for the player when he's idle.
‫And now we have to move that transition empty to our idle state.
‫And how do we do that?
‫Well, you can't simply drag it from here.
‫What you have to do is set as layer default state.
‫So now our idle state is going to be the layer default state, which means this is where it starts from.
‫So the entry and then it goes directly to our idle state.
‫Well, that's great.
‫But now we don't get to run animation.
‫Let's have a look how this will look like.
‫So you see, our guy is moving.
‫He's breathing.
‫He's moving just a little bit, if you look precisely.
‫So now what we need to do is make a transition from idle to run.
‫And of course, we need to have a behavior here or a condition here as well.
‫So there is this transition from Idol to run and we need to condition.
‫So let's add a condition.
‫But so far we only have this following condition which is not the one that we need.
‫We need to know whether the game has started or not because if the game has started, we want the run
‫animation to start.
‫So in parameters we create a new parameter.
‫So you might have an idea of how to do that.
‫You can do that with a trigger again.
‫So let's create a new trigger game started.
‫So I'm going to call that trigger and now we can open up the transition and now move or choose the game
‫started transition here.
‫Now we can click here and choose the game started trigger here.
‫So that's a condition the game has been has to be started and of course we can set that up here as well.
‫So if the game manager game started is not false, which means it's true, then we want to use the anim
‫dot set trigger with game started.
‫So that means we will start our game in here and we will start the animation in here.
‫So let's save that script and check it out.
‫And we still have the problem that we can't start the game, we can press enter and then our players
‫rotating, but we don't start the game with the game manager yet.
‫So let's do that.
‫Let's go to our game manager and add an.
‫The private void update method.
‫And in here we just check for an input.
‫So if input dot get key down and key code let's say is return.
‫So whenever somebody presses return, we want the game to start.
‫Then go ahead and call the start game method, which means means just set the game started boolean to
‫true.
‫So let's test that.
‫Let's pause the game and let's run it again.
‫So now if we start that, we will see that our player.
‫Well, let's go ahead and press enter and as you can see, our player only after a long period starts
‫to run, even though he's floating over the air already.
‫And that's not great.
‫And we can change that very quickly.
‫So let's go to our idle animation.
‫And in here, let's go to the transition and we can choose now to have an exit time.
‫So we don't want to have this exit time because now our animation will be finished.
‫And only after this idle animation, which takes almost 4 seconds, is over, we will go over to the
‫run state and we don't want that so we can deactivate has exit time.
‫So that means it will directly go to our run animation and as well we want to move our run animation
‫or our run state here just a little bit so to to the right so that it goes without any transition.
‫And if we just move the run, we'll always go back.
‫So we need to move this piece here towards the end of the Idol state and then we go to the run state.
‫All right.
‫So now let's test that again and let's see what happens as soon as we press enter.
‫As you can see, it goes directly to the running state.
‫Now you can do the same thing with this has exit to your following state.
‫So let's have a look.
‫Let's press enter and we fall and we still run two or three steps and then we do the animation of falling.
‫So you could do the same thing here.
‫Let's go ahead and change the exit time and go over to.
‫Following directly.
‫So now let's do that again.
‫Let's have a look.
‫If we fall directly or not and we can see we fall directly.
‫So as soon as we stop falling, well, we can still rotate.
‫But as soon as we stop falling or start, we will start with the falling animation.
‫All right, so that's about that.
‫Now we can start the game in the next video.
‫We will see how we can restart the game.