How to make a Keypad Passcode in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so before i start the video i want to see that i'm using an asset here are those buttons and they don't do anything this is the that is called keypad and it's completely free so let's get into it so first let's make a new folder let's call it scripts okay and inside of this folder let's make a uc sharp script let's name it passcode okay so now double click it to open it up so inside of the script we don't need those lines over here so let's just delete them and i'm gonna use using unity dot scene management okay so once that is done let's start this first of all let's make a string for the passcode and let's make it just code it goes to let's say one two three you can put whatever you want to be the password okay now let's start by making a string number eagles to know i mean uh intel number number index equals to zero string alpha and public text so that we can see what we're writing uh let's name it right now ui text eagle still okay so now we need to make a new function so let's write public void we write public so that we can access it so that we have access to it in the unity editor public void code code let's say function why not okay let's open it inside of this parenthesis let's write something like string i don't know let's say uh numbers and here let's write number index plus plus i think okay so let's write the number number eagles number plus numbers numbers eagle number plus numbers cool and let's write the ui text so that you can see what writing that text eagles too you guessed it number let's save this up and go into unity so i have made a mistake let's i write it here with that with y instead of t but i fixed it so it's text here okay okay and i also forgot to say using to engine that ui so that we can you know use the text and sorry for that now let's save it and go back into unity back in unity we are and if you go to the console you can see that we have a warning that we don't use we didn't use the code variable that is right here one and we're gonna use it later okay so first we have other things to do okay so now let's go to our passcode and let's drag it to the the canvas okay you should be seeing it here good and now let's go to the canvases let's make a text text and let's name it passcode passcode okay go here and new text and right pass pass so that the user know it has to introduce those now position now we have to move it a bit so let's just go to it okay so let's move it up here let's go to the font size and write something like 25 okay the color let's make it black completely and let's make a new a new uh raw image or image or image image or image let's just make it like this somewhere like this and make sure the passcode is like after it that you can see the passcode here okay so now it's looking good let's test this thing off of course so so if i press one two three nothing is happening you see because when i put this thing here i forgot to add the codes so the text so let's take our passcode and put it in here and down and now let's test this out till nothing [Music] that is because i didn't assign the buttons to the function so let's just go to and select all the buttons from one to zero and let's go to to here one click and let's add a function game object go to scene and right here can canvas okay now function and go to passcodes because this is the function that we've created as you can see this is the function that we've created you see pascal go to passcode and select a code function and here right we're gonna have to write for every single button something like for the button one we're gonna write one for button two we're gonna write to button three we're gonna write three and so on so once that is done let's test this thing out and see if it's working as you can see it's working but now i have no way to tell if it's the correct code or it's wrong so let's do something about that oh yes okay so the next thing we have to do is go here in the script and make a new public void let's say enter but why not and now let's check if the number if number is illegal to our code we're gonna print out [Music] it's working working save it and let's go back into unity that we are back in unity let's go to this green button over here and let's attach it one click to the can in this and pass code and our function this time is enter [Music] now let's test this thing out so let's see one two three and if we press this it's working but if the code is not one to three it's not working good so now let's implement the way to to delete this delete the code if you make a mistake or something so let's just head back into our script and write public void delete in here let's write let's just copy this put it in here and here just make null and let's see if this works forget to attach the button to the actions so just take the button add a new function passcode and delete and check if it's working for me it's working one two three this is working five is not working anymore delete this right again one two three and it's still working so this is great so now let's make something else go to build settings build settings and add open scenes now we have this scene here let's make another scene for the level 2 or something since great scene level two save okay so in the level two i'm not gonna do anything let's go back to level one to level one okay here we go okay and let's write here so if the number is equal to the code i want to [Music] to switch thing manager that load scene and let's write one [Music] let's see go back here up build settings go to scenes and take your level to it put it here and as you can see in this little corner right here you can see the values for the levels for the example our keypad demo is zero and level two is one so that's why i wrote here one [Music] let's see if this is working round two is deleting it one one two three it's working you
Info
Channel: IndieValentin
Views: 7,625
Rating: undefined out of 5
Keywords: unity password, unity c# keypad, unity code, unity switch scene via cod
Id: VRbRxiCNR2s
Channel Id: undefined
Length: 13min 22sec (802 seconds)
Published: Sat Mar 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.