• 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 /
  • Help Room /
avatar image
0
Question by adhominen · Mar 12, 2017 at 12:11 AM · scene-loadingid

How to change scene by id?

Hi.

I want to change a scene using the id of each one in the build settings, something like this:

public function BotonConceptos()

 {
     Application.LoadLevel(sceneid+1);
 }

or

public function BotonConceptos()

 {
     Application.LoadLevel(sceneid-1);
 }

I think is making the scene a var and send it to other scenes, but, i have proved a lot of things and i can´t.

Thanks so much for your help!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by adhominen · Mar 20, 2017 at 05:25 PM

hexagonius thanks a lot.

I have this.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 
 
 public class Botones2 : MonoBehaviour {
 
     public int y;
     private static int p;
     
     void Awake(){
         
         DontDestroyOnLoad(gameObject);
         
     }
     
     public void Boton1(){
     
     y = SceneManager.GetActiveScene().buildIndex;
     SceneManager.LoadScene (Random.Range(0,4));
         
     }
         
     public void Boton2(){
     
     p=gameObject.getComponent(y);
     SceneManager.LoadScene (y);
     
         
     }
     
 }
 

The button 2 dont take the int saved in button 1. Can u help me please? i´ve tried a lot and no solution yet

Comment
Add comment · Show 3 · 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 hexagonius · Mar 20, 2017 at 07:24 PM 0
Share

because y is not static and even though you don't destroy on load, I the next scene it's probably a different Botones2 class there.

avatar image adhominen hexagonius · Mar 20, 2017 at 07:42 PM 0
Share

Ok. Im really sorry i don't know so much about this.

Can you help me? I´ve tried creating a gameobject in next scene, and nothing i´ve tried works. I´ve seen all videos in youtube and readed a lot about this... i can´t.

Thank you bro for you help. If u can continue helping me, i'll be so grateful.

(excuse my english)

avatar image adhominen hexagonius · Mar 20, 2017 at 07:53 PM 0
Share

Bro it works !!!

Only changing int y to static.

Really, thanks !!!!!

avatar image
0

Answer by hexagonius · Mar 12, 2017 at 01:57 PM

 UnityEngine.SceneManagement.SceneManager.LoadScene(index);
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 adhominen · Mar 12, 2017 at 02:48 PM 0
Share

Hey u. Thanks.

What i´m trying is Load(lastlevelplayed+1).

This works the same u write.

avatar image hexagonius adhominen · Mar 12, 2017 at 07:51 PM 0
Share

the last level is probably the current one, right? that's something similar to this:

 Scene$$anonymous$$anager.GetActiveScene().index

plus 1

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

96 People are following this question.

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

Related Questions

garbage collection in between scene changes? 2 Answers

Get current scene number 3 Answers

Loading new scene, array looses elements after Start() is executed. 2 Answers

How can you queue a sequence of multiple scenes... 0 Answers

SceneManager.sceneLoaded returns scene.isLoaded as false, is this intended? 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