Switching Scenes in Unity Using a Button

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to this video where i'm going to be explaining how to change scenes with the click of a button so let's get started to start off we have our two scenes here and this is going to be the script that we're going to use before we get into coding the button first make sure that you get a file build settings and that you add the scenes that you're going to be using so i've already done that i would recommend doing that as soon as you create the scenes so inside of our canvas for scene one we are going to create our button right click ui button i'm not going to worry about the looks of the button or the position right now then if you haven't already make sure to click right create a c sharp script i've already done that i've named it scene change and here it is before we actually create the method make sure to include line four this is a super simple thing that you can easily forget and then your whole code can be messed up now we're creating a method that we are going to call when we click the button so the name is change scene we can name it whatever you want and once we click the button we want to load scene 2. so we'll save that now we have to attach the script this is really important and it's a crucial step or else your code's not gonna work we're attaching it to canvas rather than the button itself because if we create multiple buttons we'd have to attach the script to each button whereas once we attach it to canvas anything inside of it will have access so now we're going to go to the button we're going to scroll down now if you see here it says on click so whatever is listed here is going to happen once we click that button in this case it's currently empty so we're going to add a command so we're going to go to scene and select our canvas which is where we just uploaded the script no function instead we are going to select the name of the script which was scene change if you remember and then we're going to go down to the method name change scene so now once we click play we click our button there has been a change in scene thank you so much for watching this video i hope you have learned something that you can implement into your own project
Info
Channel: Unity Mechanics
Views: 17,077
Rating: undefined out of 5
Keywords: #unity, #gamedesign
Id: mAiQJoblHh4
Channel Id: undefined
Length: 2min 37sec (157 seconds)
Published: Sun Jul 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.