Unity - How to Use a Button To Switch Between Scenes

Sdílet
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

Komentáře • 152

  • @heer335
    @heer335  Před 4 lety +24

    The code used in the video is in the description below.

    • @echo9dev
      @echo9dev Před 3 lety

      Hey umm could you put it in a google drive file so people could copy and paste it

    • @carsonbartos6908
      @carsonbartos6908 Před 3 lety +2

      @@echo9dev you can copy and paste it from the description

  • @rubylikessonic2
    @rubylikessonic2 Před rokem +7

    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

  • @things990
    @things990 Před 4 lety +31

    Thank you,
    This was quick ,straight to the point and more effective than other longer videos I’ve seen

  • @OmerS25837
    @OmerS25837 Před 2 lety +4

    a very precise and straight forward tutorial, i loved it

  • @lhfirass6447
    @lhfirass6447 Před 4 lety +7

    4min with so helpful tips thanks very much may god bless u

  • @Ferenc-Racz
    @Ferenc-Racz Před 3 lety +6

    Thank you for this short, but really useful video. :)

  • @yenvalorant
    @yenvalorant Před rokem +1

    I love this video, straight to the point, no time wasting. 😍

  • @tanjironezkokamado2
    @tanjironezkokamado2 Před 4 lety +1

    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

  • @victorfiy9844
    @victorfiy9844 Před 3 lety

    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

  • @inyourhead9714
    @inyourhead9714 Před rokem +3

    For me, the function never appears as an option in the dropdown.

  • @sohamsen9897
    @sohamsen9897 Před 3 lety

    Your video was a life-saver, man!

  • @liamSp_
    @liamSp_ Před 3 lety +2

    Thank you so much you are so easy to follow unlike other youtubers lol

  • @thunder50cal56
    @thunder50cal56 Před 2 lety

    Thank you and I hope you have a nice day too 🙂

  • @DaMosseShorts
    @DaMosseShorts Před rokem

    Wow, it took me so long to find a video that actually works! ok one sub coming rn:)

  • @philcrates9476
    @philcrates9476 Před 2 lety

    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?

  • @hi4568
    @hi4568 Před 4 lety +2

    Finally a helpful video

  • @sangitachoudhury1659
    @sangitachoudhury1659 Před 3 lety +1

    Thanks sir very much this tutorial helped me very much and it worked 1000%

  • @gbm6882
    @gbm6882 Před 4 lety +5

    underrated

  • @noahrivera7996
    @noahrivera7996 Před 2 lety

    Amazing video my guy

  • @joshworks4054
    @joshworks4054 Před 4 lety +7

    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!@@@@@@@@@

  • @parabolaaaaa4919
    @parabolaaaaa4919 Před 3 lety +1

    thanks this was quite helpful

  • @splur1239
    @splur1239 Před 2 lety +1

    When I import the script it says that SceneManegement doesn't exist in namespace 'UnityEngine'. What do I have to do to fix this?

  • @duynguyenvan1329
    @duynguyenvan1329 Před 2 lety +1

    King,you drop this(crown)

  • @jozo84
    @jozo84 Před 2 lety

    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.

  • @dailydoseofinstagramdogs3246

    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

  • @soma_donat
    @soma_donat Před 4 lety +3

    Build settings won't open for me. What to do now?

  • @nabuSFEG
    @nabuSFEG Před 3 lety +1

    Thanks, this helped a lot.

  • @adigorn3249
    @adigorn3249 Před 3 lety +1

    awesome tutorial!

  • @keeab2165
    @keeab2165 Před rokem

    Phenominal video

  • @fauziarc
    @fauziarc Před 4 lety +2

    Thankyou so much!!! It works!

  • @ecoist9057
    @ecoist9057 Před rokem

    Thank you so much for this video 💗💗💗💗

  • @dovahkiin8328
    @dovahkiin8328 Před 4 lety +1

    Mersi, kyanq, utem qez

  • @12NoteOctaves
    @12NoteOctaves Před 3 lety +1

    Thank you very much!

  • @Skinnyboy148
    @Skinnyboy148 Před 3 lety

    THANKS YOU I FINNALY FOUND THE ERROR ON MY SCRIPT THANKS YOU SO MUCH BRO

  • @soumyasamal6314
    @soumyasamal6314 Před 3 lety

    Hey , Thank you for helping me. It is really helped me.

  • @Hund335
    @Hund335 Před 3 lety +1

    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

  • @9justin7
    @9justin7 Před 3 lety

    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?

  • @SammPlaysGames
    @SammPlaysGames Před 3 lety +1

    It keeps saying script class not found. What do I do

  • @omotolajoshua147
    @omotolajoshua147 Před 3 lety

    This is straight forward and helped a lot. Can you upload more of VR tutorials ?

  • @wokeupina
    @wokeupina Před rokem

    that was awesome.

  • @TWLynx
    @TWLynx Před rokem

    It works, but it keeps starting on the second scene. How do I fix that?

  • @epicdave-jz4xc
    @epicdave-jz4xc Před 3 lety

    how can I try to implement a trigger collider so i can make it without the button??

  • @Penguinmuncherdady
    @Penguinmuncherdady Před 2 lety

    nice thx helped me alot

  • @elif-du2mf
    @elif-du2mf Před rokem

    hi! does this work with touch on mobile or just mause click?

  • @airsupply1606
    @airsupply1606 Před 4 lety

    Hi admin, is it possible to change scene using voice command?

  • @adfinemrising
    @adfinemrising Před 3 lety +3

    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!

  • @yuyixian6986
    @yuyixian6986 Před rokem

    Thanks !really help
    !!

  • @micheleguardabasso8162

    i have a save system but object don't load in the correct position and can you please see project?

  • @epciBALAMITHRANS
    @epciBALAMITHRANS Před 2 lety

    thanks sir for the tutorial

  • @pinkhairblackman8141
    @pinkhairblackman8141 Před 5 lety +5

    doesnt work for version 2019

  • @mlanhem001
    @mlanhem001 Před 7 měsíci

    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

  • @anncervitillo3746
    @anncervitillo3746 Před 2 lety

    thank you so muchhh

  • @GlitchVR
    @GlitchVR Před 3 lety +1

    When I go onto the 'on click' drop down menu it doesnt have scene switcher. Any help?

    • @SlonerTheStoner
      @SlonerTheStoner Před 3 lety

      Ur code is wrong. it happend to me 2. mak sure u dont hav any mis spellins!

    • @PSPbrtag
      @PSPbrtag Před 2 lety

      Having the same problem. Did you manage to figure it out?

  • @ioanabiris3472
    @ioanabiris3472 Před rokem

    Thank you !!!

  • @jk3rrr
    @jk3rrr Před 3 lety

    Thanks man

  • @The_Pyre
    @The_Pyre Před 2 lety

    ''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?

  • @rgbgaming11
    @rgbgaming11 Před rokem

    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

  • @nikname2560
    @nikname2560 Před 3 lety

    thank you so much

  • @akkir6707
    @akkir6707 Před 3 lety

    thanks dude!

  • @deano1420
    @deano1420 Před 3 lety

    Tnx man 😌

  • @darredYouTube
    @darredYouTube Před 2 lety

    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

  • @funnymoments-nz8my
    @funnymoments-nz8my Před 3 lety +1

    THANK YOU

  • @mrdgsn
    @mrdgsn Před 2 lety

    its working. thanks

  • @notjackolio
    @notjackolio Před 3 lety +3

    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?

    • @AYANKHAN-eh6ve
      @AYANKHAN-eh6ve Před 2 lety

      I am finding that too
      if you it let me know
      it would help.

    • @notjackolio
      @notjackolio Před 2 lety

      @@AYANKHAN-eh6ve you can just add an second button in the canvas and give it the properties you want

    • @AnnoyingBush
      @AnnoyingBush Před rokem

      Make sure to turn navigation off

  • @batsygaming9743
    @batsygaming9743 Před 3 lety +1

    Hi bro I am getting a black screen when I switch scene pls help me fix

  • @joeyllorca502
    @joeyllorca502 Před 3 lety

    It is for only two buttons?? what about multiple scenes with munltiple buttons?

  • @georgeterry1450
    @georgeterry1450 Před 4 lety +5

    You should do more unity tutorials, the videos you have are very high standard

    • @heer335
      @heer335  Před 4 lety

      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 :)

    • @georgeterry1450
      @georgeterry1450 Před 4 lety

      Heer that’s a shame:( tbh any new videos would be nice because there realyyyyyyyyy good

  • @themooselord9848
    @themooselord9848 Před 4 lety

    can this work with 2 buttons going to different scenes each in same script? Or do i need to make 2 scripts?

    • @heer335
      @heer335  Před 3 lety +2

      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.

  • @Illestdoom
    @Illestdoom Před 3 lety

    LIFE SAVER!

  • @mrskull3607
    @mrskull3607 Před 3 lety

    thanx a lot

  • @OurStudioco
    @OurStudioco Před 2 lety

    Crazy amount of code just for a dang button!

  • @thefreddyguy3206
    @thefreddyguy3206 Před 4 lety

    How to make that but make it wait a little bit? after it switches ya kno

  • @kaijoswilman
    @kaijoswilman Před 2 lety +4

    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");
    }

  • @calvinwhoa
    @calvinwhoa Před 3 lety +2

    THANKS WORKS I’M SUBBED VERY COOL!!

    • @calvinwhoa
      @calvinwhoa Před 3 lety

      I have a question

    • @calvinwhoa
      @calvinwhoa Před 3 lety

      Im Used This for Lobby But I Want To Change GameModes In Play Too

    • @calvinwhoa
      @calvinwhoa Před 3 lety

      I Writed The Same Script And Renamed To SceneSwitcher1 But It Doesnt Worked

    • @calvinwhoa
      @calvinwhoa Před 3 lety

      I Changed In Script Too

    • @calvinwhoa
      @calvinwhoa Před 3 lety

      Pls Another Tutorial Vid Or Say What Can I Do

  • @001Camera
    @001Camera Před 2 lety

    I dont get any errors but it wont switch the scene when I click it

  • @notiiiprozmike
    @notiiiprozmike Před 3 lety

    TYSM

  • @raghav2032
    @raghav2032 Před 4 lety +1

    ThanUUUUUU BROOOOOOOOOOOOOOOOO

  • @chipotlegod8709
    @chipotlegod8709 Před 4 lety +3

    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

  • @EhZartyx
    @EhZartyx Před 3 lety

    Thank you so much !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @ghostarda6355
    @ghostarda6355 Před 2 lety

    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??

  • @ahinssu617
    @ahinssu617 Před 3 lety +1

    TY

  • @businessstork3279
    @businessstork3279 Před rokem

    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

  • @mayonnaiseguy69420
    @mayonnaiseguy69420 Před rokem

    Ur a life saver!!! Oh also this is a funny tutorial because the tutorial is 4:20 minutes long 😂

  • @platypus4
    @platypus4 Před 2 lety

    How to make a function when the timer goes to 0

  • @x-jbbj-x8107
    @x-jbbj-x8107 Před 4 lety +1

    you did that very fast

  • @Felix-nr1sr
    @Felix-nr1sr Před rokem

    I've done the process several times but it doesn't work

  • @borgtonhat
    @borgtonhat Před 3 lety

    I love you

  • @leoprobespiel
    @leoprobespiel Před 3 lety +1

    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

    • @heer335
      @heer335  Před 3 lety

      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.

    • @leoprobespiel
      @leoprobespiel Před 3 lety

      I Did That But Now It Says Script Class Not Found

  • @shaggydinkles1917
    @shaggydinkles1917 Před 3 lety

    i need help um..it says script class cant be found

  • @coddr4778
    @coddr4778 Před rokem

    i like the video length. 420 :)

  • @lykamejorada7685
    @lykamejorada7685 Před 2 lety

    Thankyou/!!!!!!!!

  • @KingDriftOriginals
    @KingDriftOriginals Před 4 lety +1

    dude scene switcher is nort showing in the on click

    • @GoblinArmyInYourWalls
      @GoblinArmyInYourWalls Před 3 lety

      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.

  • @tathyagarg2018
    @tathyagarg2018 Před 3 lety

    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

  • @kazmerbacsi9587
    @kazmerbacsi9587 Před 2 lety

    But how can i switch to a specific scene?

  • @im_skrunkly
    @im_skrunkly Před 2 lety +1

    remember:
    void playGame()
    doesn't work
    public void playGame()
    works

  • @AYJAYCLIPZ
    @AYJAYCLIPZ Před 3 lety

    doesnt work for me :(

  • @leoprobespiel
    @leoprobespiel Před 3 lety +1

    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

    • @carsonbartos6908
      @carsonbartos6908 Před 3 lety

      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.

    • @carsonbartos6908
      @carsonbartos6908 Před 3 lety

      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

  • @star-devil9157
    @star-devil9157 Před 3 lety +1

    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 ❤

    • @vortexstudios_echo
      @vortexstudios_echo Před 3 lety +1

      czcams.com/video/WRoIw3ktZTE/video.html it’s what I watched

    • @star-devil9157
      @star-devil9157 Před 3 lety

      @@vortexstudios_echo thanks my friend
      I already done it
      Thank you ❤

    • @star-devil9157
      @star-devil9157 Před 3 lety

      @@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 ❤

  • @im_skrunkly
    @im_skrunkly Před 2 lety

    this video is 4 minutes and 20 seconds long, nice

  • @mycomputer2757
    @mycomputer2757 Před 3 lety

    isnt working.