Unity - How to Use a Button To Switch Between Scenes
Vložit
- čas přidán 5. 08. 2024
- //Code used in video:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneSwitcher : MonoBehaviour
{
public void playGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void Back()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
} - Hry
The code used in the video is in the description below.
Hey umm could you put it in a google drive file so people could copy and paste it
@@echo9dev you can copy and paste it from the description
I love how this doesn't feel like a tutorial and just feels like you asked your friend who's good at unity to help
yush v_v
Thank you,
This was quick ,straight to the point and more effective than other longer videos I’ve seen
a very precise and straight forward tutorial, i loved it
4min with so helpful tips thanks very much may god bless u
Thank you for this short, but really useful video. :)
I love this video, straight to the point, no time wasting. 😍
you are the best 10000 likes for you I was searching for this all over youtube but u make it simple and easy thank you lots
broo thanks i couldn't figure out how to go back i was writting
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
but when i watched your video i wrote
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
and it worked thanks broooo
For me, the function never appears as an option in the dropdown.
Your video was a life-saver, man!
Thank you so much you are so easy to follow unlike other youtubers lol
Thank you and I hope you have a nice day too 🙂
Wow, it took me so long to find a video that actually works! ok one sub coming rn:)
For some reason it doesnt seem like the "using UnityEngine.SceneManager;" is actually importing that library for me to use (no recommendations for autofill and method I am making with it is not showing up for on click even after saving script file multiple times). Do I have to download an extension of Visual Studios also or is it something else?
Finally a helpful video
Thanks sir very much this tutorial helped me very much and it worked 1000%
underrated
Amazing video my guy
he, thanks for this video i needed to know and everybody else made 4 hour vid's on it so this 4 min vid is super helpful thanks again!@@@@@@@@@
thanks this was quite helpful
When I import the script it says that SceneManegement doesn't exist in namespace 'UnityEngine'. What do I have to do to fix this?
King,you drop this(crown)
im the 1000th liker
btw this is a really good tutorial you just straight up tell the soulution. it has really helped me a lot. thank you.
The build index, does that mean the scene change has to be in that order? That means I can’t click to go to a specific scene
Build settings won't open for me. What to do now?
Thanks, this helped a lot.
awesome tutorial!
Phenominal video
Thankyou so much!!! It works!
Thank you so much for this video 💗💗💗💗
Mersi, kyanq, utem qez
Thank you very much!
THANKS YOU I FINNALY FOUND THE ERROR ON MY SCRIPT THANKS YOU SO MUCH BRO
Hey , Thank you for helping me. It is really helped me.
when i drag the script and drop it over canvas it says cant add script the script dont inherit a native class that can manage a script PLS HELP
hi heer, im doing a projectm regarding to AR, and in terms of scanning image to pop up this button, can i have a word for that?
It keeps saying script class not found. What do I do
This is straight forward and helped a lot. Can you upload more of VR tutorials ?
that was awesome.
It works, but it keeps starting on the second scene. How do I fix that?
how can I try to implement a trigger collider so i can make it without the button??
nice thx helped me alot
hi! does this work with touch on mobile or just mause click?
Hi admin, is it possible to change scene using voice command?
thats the thing that i was missing!! i was really wondering why in the world cant i see the StartApp() function in Brackey's tutorial!! he didn't have the foresight that someone might have forgotten to save the script!
Thanks !really help
!!
i have a save system but object don't load in the correct position and can you please see project?
thanks sir for the tutorial
doesnt work for version 2019
But this is load scene all the obj will reset can you switch scene but everything on the 1st scene still there same as when we left ? pls
thank you so muchhh
When I go onto the 'on click' drop down menu it doesnt have scene switcher. Any help?
Ur code is wrong. it happend to me 2. mak sure u dont hav any mis spellins!
Having the same problem. Did you manage to figure it out?
Thank you !!!
Thanks man
''SceneManager does not contain a definition for LoadScene''
''SceneManager does nto contain a definition for GetActiveScene''
the script is not working for me and those are the errors Im getting, what can I do?
Thanks for providing this , as you know its an old video now but it helps a lot, i am having a problem here, an error of 2 event systems.
How do i deal with tha
thank you so much
thanks dude!
Tnx man 😌
At me it dossnt work (i put play game in the action list ) i put in the build thing the scenes and doesnt work as well
THANK YOU
its working. thanks
Great tutorial! Exactly what I needed! But 1 question, If I want 2 buttons on the same scene how do I do that? Do I have to create another canvas and another script with other scene numbers?
I am finding that too
if you it let me know
it would help.
@@AYANKHAN-eh6ve you can just add an second button in the canvas and give it the properties you want
Make sure to turn navigation off
Hi bro I am getting a black screen when I switch scene pls help me fix
It is for only two buttons?? what about multiple scenes with munltiple buttons?
You should do more unity tutorials, the videos you have are very high standard
Thanks for the kind comment! Sadly I don't use Unity much these days and I've forgotten most of it. Though I'm glad that this tutorial is helping a lot of people out :)
Heer that’s a shame:( tbh any new videos would be nice because there realyyyyyyyyy good
can this work with 2 buttons going to different scenes each in same script? Or do i need to make 2 scripts?
Sorry for a super late reply. Yes you can, all you need to do is make another function. For example:
public void clickButton1()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void clickButton2()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
You just need to choose the correct function when applying it to the button. KEEP IN MIND, these two functions are just to show, you need to modify them yourself.
LIFE SAVER!
thanx a lot
Crazy amount of code just for a dang button!
How to make that but make it wait a little bit? after it switches ya kno
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneSwitcher : MonoBehaviour
{
public void playGame()
{
SceneManager.LoadScene("SCENE NAME");
}
public void Back()
{
SceneManager.LoadScene("SCENE NAME");
}
Thank you so much.
ty
@@bobthebuilder5434 np
THANKS WORKS I’M SUBBED VERY COOL!!
I have a question
Im Used This for Lobby But I Want To Change GameModes In Play Too
I Writed The Same Script And Renamed To SceneSwitcher1 But It Doesnt Worked
I Changed In Script Too
Pls Another Tutorial Vid Or Say What Can I Do
I dont get any errors but it wont switch the scene when I click it
TYSM
ThanUUUUUU BROOOOOOOOOOOOOOOOO
What if I have multiple buttons and want each one to go to a different level
Edit: What I did was I made a script for each button and just added one more number to the build index value every time
Yeah that should work correctly.
Lol you are fast to reply!
Thank you so much !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hey nice tutorial! but i have a problem, when i switch the scene and switch back i cant press any buttons can Someone help pls??
TY
If you were to have multiple scenes to click through, could you theoretically just copy paste this code into each button's script? Very helpful video by the way
Ur a life saver!!! Oh also this is a funny tutorial because the tutorial is 4:20 minutes long 😂
yay funny minute
How to make a function when the timer goes to 0
you did that very fast
I've done the process several times but it doesn't work
I love you
Cant Add Script behavior while compiling please wait until compilation has finished and try again.
When Im Dragging The Script On :( Plz Help I Dont Know Anything About Coding
I believe the error message is telling you that you have to hit the pause button on the top before you can add the script. At the moment it seems that the program is running, meaning that the play button on the top is clicked.
I Did That But Now It Says Script Class Not Found
i need help um..it says script class cant be found
@@cr2ft3r thanks bro
i like the video length. 420 :)
Thankyou/!!!!!!!!
dude scene switcher is nort showing in the on click
I'm also having this issue. I'm so tired of Unity having all these built in 'solutions' that take just as long to learn/diagnose as it would be to build my own in house solution. Which is exactly what I'm going to do now.
This took me sooo long to figure out because I was only seeing what's wrong with the SCRIPTS turns out I forgot to add in the scenes in the build
But how can i switch to a specific scene?
u found a solution yet?
remember:
void playGame()
doesn't work
public void playGame()
works
doesnt work for me :(
Cant Add Script Component SceneSwitcher becuse the script class cannot be found make sure that there are no compile errors and that the file name and class name mach
When Im Draggin Onto Canvas But I Have No Errors BTW
I had the same problem, the way I fixed I just didn't rename my C# file and it worked, I also had to put the file to the button instead of the canvas. Now I am stuck with it saying it cannot find a scene with build index 1.
nvm I solved this by going to 'file' then 'build settings' then clicking 'add open scenes' and then added all the scenes, hope this helps
Sir I need help I'm beginner
I'm making car game I forgot to put exit button in the game screen
For example : I'm playing the game if I press the exit button , it come to the main screen
How can i make it sir
Please reply ❤
czcams.com/video/WRoIw3ktZTE/video.html it’s what I watched
@@vortexstudios_echo thanks my friend
I already done it
Thank you ❤
@@vortexstudios_echo but one problem I'm facing one issue
I'm getting some messages like this when I press the build setting
I'm importing this .exe file in outside the assets
👇👇👇👇👇👇👇👇👇
UnityEditor.BuildPlayerWindow+BuildMethodException: Build failed with errors.
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x001b9] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:162
at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x00050] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:83
UnityEditor.HostView:OnGUI()
Can you help me please ❤
this video is 4 minutes and 20 seconds long, nice
isnt working.