Learn How To Jump with UI Buttons in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's joshua gaming in this video today we made a jump button which you can double jump and you cannot jump again until you have reached the ground so hopefully you enjoy this video and make sure to subscribe and leave a like so let's get into it hey what's going on guys it is me jack again with another video today i'm gonna be making a video basically a parody on my last video which was moving your player or a part with a with some ui buttons in unity and today we're gonna be jumping with ui buttons so if i go and press play here you will see when it's finished loading on what we did in our last video and as you can see you can move right and left with these ui buttons and today we're gonna be jumping with ui buttons and more specifically double jump and it's not really hard it's let's say very pretty easy level of codings in c sharp so let's get into visual city code we're going to go to our move script we last used that are made last video and we're going to start scripting okay visual studio code is open and we're going to start by making another variable in in our first lines of code i guess so it's going to be a public but not private public float um jump speed says the how fast player is going to jump jump speed as well speed wrong you stupid equals i wanted my player to jump the speed is five so let me just put five there and we're going to have another variable which is a b variable let me just write that bool um is grounded is grounded and then just put this and another bull which is bull can double jump so can double jump there we go and another one which is not going to be build this time is going to be a public float which is public float um public float there we go delay before double jump delay if i'm erasing for some reason b4 b4 double jump there we go this is the delay or the time sorry might just plug the reference again or just i don't know what happened so it says public float delay for double jump so this is so how much time you can um jump after you have on the ground and we're going to start coding in your last and right in this line if i come down here we're going to first have a void on collision so void on collision enter and enter enter 2d and pressure 2d dot not dots parentheses and collision 2d religion this collider collision 2d there we go and then other i'm going to come down here and put this and there's there was gone or the red lines so it's still being arrow or it's going to have a if statement if parentheses if other dot gameobject dot tag equals equals to ground which is what we're gonna if i come back in unity moment okay we're in uni and i come to my ground we're gonna have to make a tag which go here and add a tag and we're gonna name this tag ground and save it there and these are your layers but we're not going to be doing that today so it's going to be using the tag ground if you come back to this and you go back to tag you're going to see the ground tag what you just made and select it so the tag whenever you touch this it's going to be ground if we go back to vs code um we're going to come here again and make some two curly brackets and we have another statement if it is grounded is grounded equals true so when a player touches the ground um the a is grounded statement will be it is grounded value variable will be true and the can double jump will be false equals false there we go and we're gonna come down here once more over here and make another statement which is gonna be and make another statement it's gonna be public void public void jump we're going to call it jump button jump button here we go and we know we're going to parentheses here and come down put to curl brackets or one into somewhere put it and we're going to have it's going to be if if and parentheses is grounded and some curly rex again is grounded false so basically if the player is jumping moment when they press the jump button and if the player is grounded and it says right here is if i can write this is grounded will be false this there we go another line which would be the rb velocity which is rigid body we'll put um up here if i can find it yeah there is body components so we're gonna have let's say rb dot velocity equals vector 2 up vector 2 dot up then times jump speed so this is how fast the player is going to jump or your object you have this and come down another line which can have invoke so put a capital i it i can't put a gabriella for some reason there go invoke enable double jump so enable double jump there we go that's gemma dump and we'll have a comma comma right here and we're not delayed for double jump thing will be but delay for double jump which already stated that up here this is the time we're gonna take the job okay once we have that we just put this there this here and we're gonna have another statement right below this i'm pretty sure yes right below this which is if can double jump can let me just get out of this and yeah there we go can do down these curly brackets here and we're gonna have rb dot velocity equals vector 2 up you can copy this here but i feel like it's better just write it because 2 dot up and time the jump speed there we go and another wait i forgot to put this quotation mark i'm sure it's called wait no that's not what it's called um we're gonna put a can double jump equals false there we go and we're gonna have that once we have that we're gonna have another line i'm pretty sure this is the final line and then we will make the ui buttons um so come down here and we'll have a void enabled up jump void enable double jump which is already all the kirks because we mentioned it right here and i have four double double jump parentheses there and some screw curly brackets or squarely lines not screw whatever you call it and can double jump equals true can double down equals true there you go once you have that and uh this here and you should not have any arrows or anything it says it's not safe critical or control s not critical um then this should be a whole entire script so if i go back into unity and we're gonna make the ui buttons as it says it's compiling the script so we made it from vs code so when it's done i'll get back to you it's finished compiling now we will go to the canvas and we're going to make our jump button so we're just going to move the right button over here right beside the left and duplicate it put it right here if you want if i can come down that's good enough i guess and we're going to name it jump button if i can go dumb button and we're going to have this and we're going to change the text of it which is inside of this the object in the change of text which is right here jump to jump and if you're going to change the font you can add your own fonts to this you can do all sorts of things if you want but we're just going to keep that normal fund and if you just press this game thing right here you will see this it's not playing the game it's just you need a preview of the game and you can see how the buttons will look it's this is a bit too high position but it's already so you guys can change it if you want so once you have that we are going to wait i spelled jump button wrong one sec and change this there we go and now if you see same thing what we did for last video if you come down here you i saw you saw i have a event trigger and i have a pointer up so if i come well we're not going to have pointer output i have an event trigger which is the same thing so okay as i said we're going to come down here and we're going to remove this one this event trigger and we're going to go into this and go to move and we're going to look for jump button which should be right above pointer down left and right below it's cancelling bulk so jump button and once you've selected that the whole thing should be working out so if i go into play while this is loading there go i fall down and if i jump i can jump and let's see if i can jump twice so one two and then i can't jump again once i'm on the ground so we can turn left right and you can jump while you're moving but i'm using a mouse at the moment so i can't really do that but on mobile if you're making a mobile game like this i'm pretty sure that's where you're gonna need these ui buttons you can just jump right there go so move right and jump so that should be everything now so thank you for watching hopefully you like this and if you did please leave a like and subscribe and that's all goodbye [Music] you
Info
Channel: Jadtru
Views: 6,086
Rating: undefined out of 5
Keywords: Unity, Jump, Jump With button, button, 2021, 2022, double jump, gone wrong, gone right, funny, tutorial, Jadtrugaming, help
Id: brGJn6N7qdU
Channel Id: undefined
Length: 10min 50sec (650 seconds)
Published: Tue Oct 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.