Unity Change Scene With Button - EASIEST Method

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone uni tips here in this video i'm gonna show you guys how you can swap between scenes using a button so i've got this little ui set up here if you don't know how to do this and if you don't know how to use buttons you can check out a previous video of mine it's on my channel and in that video i set up the ui and i explain exactly how the ui and the buttons work so in this video we're just gonna make a new scene so go into your scene folder create scene call it scene two and then the main scene i'm gonna call it scene one and then you go into your new scene you go to file build settings and then you click add open scenes as you can see my first scene isn't in here yet so i'll go to that one and then also press add open scenes just drag scene one to the top and you can just close it again so now we're gonna make a script that manages the scenes it's gonna be the easiest script ever so just create a new script i'm gonna call it scene manager script one thing that you wanna avoid is calling it scene manager because if you just call it that it's gonna cause issues it's the term that unity itself uses i didn't know that at first but now i do so i'm telling you guys so you can avoid the mistake i'm gonna open up the script [Music] all right so then first you want to import a new library so you want to do using unity engine dot scene management and then you can delete the start function you can delete the update function we're not gonna need them you just wanna make your own new functions so you wanna make it public and then call it something like load scene and as a parameter you want to give it the string scene name right so then you just want to do scene manager dot load scene and you want it to load the scene scene name so you fill in your own scene name there right so if you have your script like this we just need to apply it onto the button so let's create a new button for this i'm gonna attach an image to it i'll just use this one and i'll change the text to seem to make it a bit bigger so that we can actually see it right so what you want to do is go back into your button and then you click the plus here and then you have to attach your script to a different object so i'm gonna attach it to my canvas that's not the right one attach the scene manager script and then on your button you can drag the canvas into it okay so you have to go in here go to your scene manager script and then just select your function load scene and then in here you need to type the scene that you want to load exactly the way it is it's case sensitive and everything so as you can see it's already there so i'm gonna press play and in this second scene i've just made the same button except it leads to scene one exactly the same steps but you put scene one here as well so let's see if it works and there we go [Music] now that one doesn't work for some reason let's check it out uh i've not input scene one yet so there you have it a script to change between scenes with a button i hope this helped if you've got any suggestions on what i should make a tutorial on please leave them in the comments below sienna
Info
Channel: Unitips
Views: 11,304
Rating: undefined out of 5
Keywords:
Id: zQH7RRb3CnY
Channel Id: undefined
Length: 6min 8sec (368 seconds)
Published: Thu Oct 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.