Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Pillowfighter9 · Aug 17, 2016 at 04:39 PM · scene-switching

How to change a scene from a button

It sounds simple, but ever since Unity 5 rolled in everyone's been giving me false information about

Application.LoadLevel WHICH IS OUTDATED

And now I'm stuck here with a half developed game, frusterated out of my mind thinking about scrapping this entire game because it's entirely based on buttons!

Please.. All I want is some clarification. All the tutorials are outdated. All the forums are too. I just want to change scenes on a button tap. All I require out of the veterans of Unity.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pillowfighter9 · Aug 25, 2016 at 04:47 AM 0
Share

Alright, I've figured this out. Because I'm not very well versed in program$$anonymous$$g, I didn't know that the "Class" had to be the same name as my script. Or something like that. Because as soon as I changed the class name to my script's name.

Thanks for all who responded to this thread and helping this cat out.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by skiedude · Aug 17, 2016 at 08:41 PM

What errors are you getting and your current implementation? From what I found across the interwebs is making sure you add the 'using UnityEngine.SceneManagement;' for Unity 5+. You can call the scene by name in the first example, or just increment your current buildindex if you have your flow sequentially.

Examples pulled from http://forum.unity3d.com/threads/unityengine-application-loadlevel-int-is-obsolete.372915/

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Collections;
 
 public void GoToSceneThree()
     {
         SceneManager.LoadScene("scene_three");
     }
 
 public void NextScene()
     {
        Scenemanager.GetActiveScene ().buildIndex + 1;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mad_Tiger_2409 · Aug 17, 2016 at 08:20 PM

@Pillowfighter9 Look at the documentation: http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html

You can see on the top of the page information that you are looking for: "Use SceneManager.LoadScene"

I hope that I helped :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mukabr · Aug 17, 2016 at 05:49 PM

You have to use https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html now

Something like this:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
     
 public class YourClass: MonoBehaviour{
     public void OnButtonClick(){
       SceneManager.LoadScene("scenename");
       }
     }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pillowfighter9 · Aug 17, 2016 at 09:39 PM 0
Share

Yeah, it doesn't work. I've tried everything in my own knowledge and the knowledge of the community.

I've attached this script as it's own component and as a trigger with the "Button Press" window in the default button's properties.

No matter what I do, I cannot work this out.

avatar image skiedude Pillowfighter9 · Aug 18, 2016 at 03:43 AM 0
Share

I think I found what might be your issue.

When I got home tonight I spun up 2 quick scenes and tried out what I posted above. I named them 'first' and 'second'. Now I didn't use a button, just a keydown, but it should still work with your button.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class controlme : $$anonymous$$onoBehaviour {
     void Update () {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R))
         {
             Scene$$anonymous$$anager.LoadScene("second");
         }
     }
 }

I put a red cube in my second scene so I knew I had moved to the next one. Just having that in my code it wasn't working. I checked console and saw:

 Scene 'second' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
 To add a scene to the build settings use the menu File->Build Settings...
 UnityEngine.Scene$$anonymous$$anagement.Scene$$anonymous$$anager:LoadScene(String)
 controlme:Update() (at Assets/controlme.cs:17)
 

So I opened up my build settings, added my two scenes to the build settings and then closed the build settings window and tried again, voila! worked like a charm. $$anonymous$$ake sure the scene you are moving to and from are added to the scenes that will be built when you choose to do so ( you don't have to build, just add them and close the build window)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

+= sign not working properly unity 1 Answer

SceneManager.GetAllScenes() only returns the current scene 3 Answers

Custom 'wipe' Transition between scenes 1 Answer

Problem in loading death menu scene 1 Answer

UnloadSceneAsync() does not seem to work with additive scenes. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges