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 /
  • Help Room /
avatar image
0
Question by Jalah_LLC · Mar 28, 2016 at 07:34 PM · load scenelevel loadlevel selectindexing-array

Is it possible to have one script to call upon levels please help!!

Hey everyone I was wondering if anyone could help me or point me in the right direction. I have a script for my game for loading a specific scene when clicking on the correct object. When I click on the right object, I have it go to a win screen. When I click on the wrong object, I have it go to a lose screen. Each of those scenes have a button for next level or reset level. I have a script for loading the next level as shown:

 #pragma strict
 
 
 function Start_Game_Button () 
 {
     Application.LoadLevel("Level 1");
 }

My question is do I have to make that script for every scene to load the next level/scene (ex 1 2 3 4 5 etc)? Or is there a way to make a script that will keep going to the next level without me having to write the script:

 {
     Application.LoadLevel("Level 1");
 {
     Application.LoadLevel("Level 2");
 {
     Application.LoadLevel("Level 3");
 {
     Application.LoadLevel("Level 4");
 }

if anyone can help me or point me in the right direction I would greatly appreciate it. Thank you.

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

Answer by Ygedey · Mar 28, 2016 at 10:25 PM

You could make a function in your script which moves to the next level by using the index that the scene has in your build settings.

If you read this page SceneManager you can see that SceneManager.LoadScene (Note that SceneManager.LoadScene has replaced Application.LoadLevel) can pick a scene from the index that it has in the build settings.

This means that if you keep track of the index of the scene you are in, you could simply do:

 function LoadNextLevel(){
     currentIndex++;
     SceneManager.LoadScene(currentIndex);
 }

Edit: As Toon_Werawat mentioned in another similar question, you should be able to use

 SceneManager.LoadScene(SceneManager.GetActiceScene().buildIndex + 1);

Which would save you from keeping track of the current index in a static variable.

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 Jalah_LLC · Mar 31, 2016 at 07:17 PM

Ok thanks for your help! I did try what you suggested as Toon_Werawat stated, but since my index includes a "Lose Scene" and "Win Scene", it kinda messes up the buildindex counting up. I found this:

 The only way to accomplish this that I have found is to make multiple game over scenes even if they look the same.
 
 Then position them in the build index underneath each level. So "level 1" is above "Level1GameOverScene" and "Level 2" is above "Level2GameOverScene" and so on.
 
 Then add the script that says SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex -1); onto The "Try again" text for example in your GameOver scene.
 
 And attach another script onto the thing that causes the game to be over that says - SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
 
 This way the scenes are relying working with each other as long as they are positioned correctly in the build index. This is the only way I can think of that is easy but I can almost guarantee that someone experienced can find a much easier way using code I've never even heard of.
 
 I hope this helps others in my situation but if not, good luck finding a solution to your problem. :)


however, I feel that it is not efficient, and I am sure there is a better way. Is it possible to have a win and lose screen load up within a level scene? That way it is not considered a "scene". Like how in flappy bird when you die, a popup comes up saying game over, despite still saying in the same scene. Does anyone know? Any help I would greatly appreciate it.

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 Ygedey · Mar 31, 2016 at 08:17 PM 0
Share

What if you put your "Game over" and "Win Scene" before your actual levels in your build settings? Then, when you want to start playing through the levels, load the first level with its name, and then let them roll on. If the player loses, use the name of the game over screen to head to that scene.

avatar image Jalah_LLC Ygedey · Apr 02, 2016 at 12:32 AM 0
Share

I can try that! When you say load the first level with its name, then let them roll on, what do I do to accomplish that? Since the "Win Scene" has a next level button it has this:

 import UnityEngine.Scene$$anonymous$$anagement;
 #pragma strict
 
 
 function Start_Game_Button () 
 {
     Scene$$anonymous$$anager.LoadScene ("Level 2");

so what script can I do to let the rest roll on from the build index without contradicting this script?

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

52 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

Related Questions

Scene is loading in Game Mode, but not in the build. Why? 2 Answers

level manger and starting scene will not work together 0 Answers

How can i get the value of the Scrpit what is attached on the Image 0 Answers

Creating a very Long Level Select Scene 0 Answers

How to GetComponent for SteamVR_TrackedObj when script not attached to controller 0 Answers


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