In the previous lecture, we learned how we could retrieve and use the mouse position to make a character follow the mouse around. In this lecture, we're going to learn how we can respond to mouse button input from the player. And before we do, you should take an in video quiz about mice. Okay, the answer from the Unity perspective is three, left, right, and middle, for the mouse buttons. Though of course, gamers understand that that's not necessarily all the buttons you get If you have a R.A.T. mouse, or a Razer Naga, or something like that. So for us, we'll only deal with up to three mouse buttons, but we know that some mice have way more than that. Okay, let's go to Unity, and see how we can process mouse button input. Now we're going to change our game so that we change characters when the player clicks the left mouse button. So I've already added a new script called CharacterChanger here. And I've attached that's script to the main camera. So, this is not really functionality that should live inside a character, right, because it doesn't know about other characters. So it doesn't really make sense to add this to a particular character to change to a new character. Instead, this is a higher level sort of game level function. And so, those kinds of game functionality go into like the main camera, or sort of the higher level game manager script, rather than attached to a particular object. That's really good object ornate design. So, this character changer script, that's a higher level functionality attached to the main camera has four different fields that I have populated with the prefabs for the four different characters. So that I can change to one of those other characters when the time comes. Let's go look at that script. So here are those four fields that I mentioned. We also needs to keep track of what the current character is, because when we change characters, we're going to change to a new character at the same location the current character is at. If we were going to sort of spawn that new character at the origin in the center of the screen, then we wouldn't have to do this at all. But, it looks nicer to actually do it where the occurring character is. To start method, just put Character0 into the game at the center of the screen so that we start with the character in the game. And then Update is called once per frame but obviously, there's nothing here yet. So the first thing we need to know is, how can we tell If the left mouse button is clicked? And to find that out, we of course, go read the scripting reference documentation for the input class. And here's our documentation. This time, we actually do need a method And the method we need is GetMouseButtonDown. So this returns true, during the frame the user pressed the given mouse button. So we'll click on it to learn a little bit more about the method. And we see that we provide a button number. And if you go down to the example here, you can see that button 0 is the left mouse button. So, we now know that we can use exactly this if right here to find out whether or not the left mouse button was pressed this frame. We don't care if the player holds it down or anything, we just want the first time it's pressed, and that's when we're going to change the character. So I will say change character, On left mouse button. So if (Input.GetMouseButtonDown(0)), we saw the 0 is left. So I'm going to do two different things here. First, I'm going to save the position the current character is at, and then I will instantiate a new character at that position. I will also destroy the current character, because we're not trying to stack characters up, we're just trying to change characters. So the position is just the current character's transform.position. And now I can Destroy, currentCharacter. And that will remove the currentCharacter game object from the scene. I'm going to type in the code that generates the new random character and then we'll talk about it. First, I generated a random number that's 0, 1, 2, or 3. Remember the upper bound is exclusive on this method call. And then I put it into prefabNumber, a local variable here. If that prefabNumber is 0, I'm going to set current character to Instantitating prefabCharacter0 at the position Quarternion.identity. And I do a series of else ifs and then else to do that for prefabCharacter1, 2 or 3. This can be an else because if the prefabNumber is not 0, 1 or 2, it has to be 3, so that instantiates are new current character. So of course, I need to save my script to make sure that when I run it in the editor, it actually uses this most recent version of the script. And I also need to remove this character 0 from the scene, because remember, the start method of the character changer script is going to add one of those right when we start the game. So I run the game, and I move the character around and she clamps fine like she use to, and when I left-click, I get a different character. Now I just left-clicked there and it didn't change characters that doesn't mean the code is broken. It means that, it's generated a random prefabNumber here. And the prefabNumber it generated happens to be the same prefabNumber of the character that was currently there. And so, this is one of those instances where you might believe the game isn't working properly, but it really is the nature of random numbers is, we might general the same random number twice in a row, or even more if we're really unlucky. So there you go. Now we have processed the left mouse button to change the character in our game. To recap, in this lecture, we learned how we can process mouse button input to use it within our unity games.