 One last thing about virtual axes is we have these methods get button down get button and there's also get button up Which is not seen here and for these methods you specify a virtual access And what you go back is a Boolean value either true or false and you get true when the access value is non-zero But only non-zero due to button or key input It'll never be true because of joystick access input or because of mouse access input only because of buttons and keys So here in our code We're querying get button down horizontal that'll be true in the first frame where we push one of the keys It causes the horizontal value to be either positive or negative just anything other than zero Whereas get button Will be true in every frame where the horizontal virtual access value is non-zero Thanks to button or key input and then we also this fire one access which is defined here Let's fire one this fire one defined for joystick button zero and this fire one defined for left control and also mouse zero So let's play the game here Okay, so there's our fire one events because mouse zero is bound for fire one And so we got first the fire one down and then as we held it down for a little bit on subsequent frames We got these we see fire one. That's from that's from the get button rather than get button down That's what all these subsequent logs are from. Let me just refocus again and For the horizontal and D are both mapped I can hit a or D or left arrow or right arrow because those are all bound as buttons for the horizontal axis But if I take my gamepad here where the left stick x-axis is mapped to the horizontal virtual access I can go left and right here and nothing's happening Because as far as the get button and get button down and up methods are concerned. It doesn't count So again, there's the stock pop-up window at the start of a unity game where you can map your inputs for the virtual axes Well, if in your game logic, you just use get access or get button down and get button up If you just use those four methods for all of your input queries Then the user should be able to from that menu reconfigure their input However, they like and you don't have to write your own key binding menu. That is the idea On the other hand, if you're going to do your own key binding menu in game You're probably better off querying input through get key using key codes because remember you can query mouse buttons and joystick buttons through those except for joystick access movement and Mouse movement input you're gonna have to handle that through virtual axes and then somehow in your game logic Allow the user to configure those inputs how they like like say they should be able to invert their axes if they so choose It's a little awkward and it doesn't seem to be what they had in mind when they design unity But it totally can't be done. And as I mentioned, we should be getting a new input system sometime in the next year Which should address these problems Now, what if we want a game to have cursor driven input? Well, actually by default we have an enabled cursor. In fact, I'm going to here build our game and run it in full screen And we still have a visible cursor here even in full screen mode And in fact, I could just mouse out of the window under my second monitor. You can't see that But I'm just moving the mouse over to my other monitor here So I'm quit out of here We can disable the visibility of the cursor through the cursor class which has a Static property called visible which will set the false its default values true But now we'll set it false in the start method of our script And so now if I play the game even in the editor now when the cursor enters the window It is hidden as long as it's within the window. It's still there logically. It's just you don't see that So here it pops up out over here What I might want to do though is Confine my cursor to the window And I can do that by setting the lock state property, which is expecting the cursor lock mode enum value The default is none such that I can just freely move the cursor in and out of my window even when it's full screen I see when I have multiple monitors, but then if I make it confined When I run my game and give it focus the cursor will be stuck within the confines of the window I can't just mouse out We want the cursor to be visible. So I'll comment that out save my code Come back here and within the editor. I don't think the setting has any effect. I think it just gets overwritten So I give focus here and yeah I'm not sure it actually even does anything in the editor, but if you want the game as a proper standalone and run it in windowed mode here 1080 windowed play and okay Game loads up and okay my cursors confined But Unexpectedly we tab out and we tab back and oh wait my my cursor is free now I think what happens is that anytime you tab out The cursor lock mode gets reset to none So what we want to do is we want to reassert every time we give focus back to the application We want to reassert the lock mode to being confined and we can do that In an event called uh on application focus There it subsets out for us and then when focus is true This is fire to believe both when you leave focus and gain focus And so when focus is true that means we just gain focus and so we want to just reassert this to be confined And this should fix our problem. You know quit the game Rebuild and play in a window It's loading up cursor is not confined until that initial start But now it's confined It's a little weird how it kind of pokes out at the bottom here. I don't know if there's a way to address that Anyway tab out come back and and reconfine In fact, let's see. I'll tab out and make sure the cursor is not within the window confines If I tab back it snaps my cursor back within bounds. There we go So that's probably what we want if we're doing a cursor driven game And I'm going to quit this out I'm going to assume that on application focus fire is like within the first frame when our game loads up I believe that's the case. I'm going to curious. Let's let's try that make sure that's the case. So I'm going to build again Make sure my cursor is outside the window. So what happens when the game loads up Play are you going to snap my cursor in? Yeah, I could snapped in okay So on application focus does fire on that first frame. So that's good So we don't need it in our start just in that one method And aside from confined to none. There's also locked Locked will actually override visible when you're in the locked state your cursor is never visible But it also locks it to the center of the game window So here we're just going to play the game again So it happens And yes, your cursor has disappeared and now stuck in the middle This is probably the setting we want for like a first person shooter Or most any game where we just want to totally disable the cursor The reason you want locked mode rather than just cursor dot visible equals false and confined You think this is the same thing, but there's one little detail that makes that undesirable run in windowed mode And okay as soon as the game starts up. Okay, my cursor has disappeared. It's confined to the window. I can't drag it out Very small thing here. It'll be Evan in a second If I drag my cursor up to the right most window up see that My cursor is invisible, but it's actually over the window bar And so I could very easily on accident Maybe I'm using my mouse for like first person shooter controls input. Um, if I'm going to click right now Close my game So that's why you want to lock your cursor for like a first person shooter rather than just make it invisible and confined Something you'll probably want to do if you have a cursor in your game Is set what the cursor looks like rather than just having your system default like this arrow And to do that you'll import a texture to use as your cursor icon I brought in this handpane right here And I set the texture type to cursor It's default by default, but I set it to cursor make sure to then apply that change And then so we kind of access to this texture in our code There are ways we'll talk about later where you can just programmatically refer to assets from your code But the simplest way to do it now is that for our manager script I've added a property called cursor texture And I've dragged the hand to that field And in the code what that is it's this public field of type texture 2d And that's the simplest way to get a handle to a texture in the script And so now if I want to use that cursor texture to set on my cursor Uh, I call this method the cursor static method set cursor Specify first the texture we're going to be using This is specifying the mode of how the cursor is drawn whether it's done in hardware or software That distinction between hardware and software cursals. Um, I won't get into here But we generally want auto there's really never much of a reason to use software anymore these days So we'll just make this auto and this argument in the middle is a vector 2 value A vector 2 is like a vector 3, but there's only an xy chord rather than also a z chord So this is x of 0 and y of 0 And this is specifying where on the texture icon we want the clicking point to be You can have a cursor texture that looks like whatever you want like say a hand And then you need to specify what the coordinate of like the tip of the the pointing finger is Because that's not necessarily the very top left of your texture on the hand icon I've chosen the coordinate I want to somewhere over here. I don't even know what the dimensions of my hand icon Is this like a hundred by a hundred or something? So this is probably x of 50 60, I don't know and then a y of about zero That's probably what I want from a coordinate, but I'm just gonna leave it 0 0 because we don't care right now So I'm going to save this And we don't want to walk our cursor state and we definitely want a cursor to be visible So let's comment that out and now let's run the game And we should see the change in the editor even so my regular cursor But as soon as I drag into the window now it's changed to my custom hand icon And let's just verify this let's run this as a window application and see this in action play and then There we go, there's our hand icon And I assume if we tab out the cursor gets set back to its default That's why we're setting the cursor in an on application focus event Because we want to make sure it gets reasserted every time we give our application focus I assume that's the case. I'd actually have to test to make sure that's actually necessary But this seems to be working the only thing not proper right now Is that when I click the click point is not the tip of the finger It's actually the top left of the image. So It's kind of floating off in space there. We would want to adjust that coordinate So it lines up with the tip of our our index finger here Last but not least we of course want to read the position of our cursor in our game window And we can do that with the static property of input called mouse position It returns a vector 3 In which the x y values are the x y coordinates within our game window over the cursor's position With zero zero being the bottom left and the top right of our window being determined by the resolution If our resolution is 1920 by 1080 then the top right of our window is 1920 1080 And in fact when we read the mouse position if our cursor is outside the bounds of the window We still get a coordinate. So if our cursor is to the bottom left of our game window It'll actually be negative x and y values And if our cursor is above and to the right of the top right of our game window Then the x and y values will actually exceed our our current resolution So let's see this in action In our update when I click the mouse button down for the primary mouse button We're going to get the current mouse position and log it out. So let's just see that in action Play and then hover over the window and if I click We're getting Yeah, strangely we get a vector 3, but the z chord is just always zero. So it's a little strange there But that's how it works And I don't think here because I'm relying on a click within the window It shouldn't do anything when I click outside of it. I'm pretty sure. Yeah, so The way I wrote the code is we couldn't only see the coordinates within the window But here it's a bottom left that should be about zero zero. Yeah And then it seems like our window right now the resolution is something like 900 by a little over 500 Here let's actually make the logging unconditional. So just print out every frame It'll flutter log a bit, but then you'll be able to see that's when it recompiles So now you see the mouse position as you can see is exceeding our total resolution And if I could sneak down here below the bottom left, am I getting yeah, I'm getting a negative y value at least there I'd have to move this window over and then put my mouse down here And are we getting there? Okay. Yeah. See the x and y now are negative