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 Pejovski · Nov 07, 2015 at 04:32 PM · buttonloadloadingloadlevel

Load Level script problem

So i have MainMenu scene, EndLevel scene, and 8 Levels scenes (Names: Level01, Level02,Level03...). On MainMenu and EndLevel i have button and added the function StartGameNew this is my code:

 #pragma strict
 var levelNumber = 1;
 function StartGameNew()
 {
     Application.LoadLevel("Level0" + levelNumber);
     if(levelNumber <= 8)
     levelNumber++;
     else levelNumber = 1;
 }

The problem is here when i click on the button play again this error pops up: Scene 'Level00' (-1) couldn't be loaded because it has not been added to the build settings or the asset bundle has not been loaded. To add a scene to the build settings use the menu File->Build Settings...

Why it wants to load Scene 'Level00' ? not Level02? how to fix this where is the problem in my code?

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 Statement · Nov 07, 2015 at 10:57 PM

Scene 'Level00'

 var levelNumber = 1;
 // ...
 Application.LoadLevel("Level0" + levelNumber);

levelNumber must then be zero. If you for example originally had levelNumber as 0, or changed levelNumber in the inspector to 0, it will retain that information.

Why it wants to load Scene 'Level00' ? not Level02?

Well, first I don't understand why you expect it to load Level02. I could agree that you could expect it to load Level01 because levelNumber is 1 in the script. However levelNumber is a public, serialized variable and if you check the number on the script on the inspector, you'll find out it's 0. Why? Because one power of Unity is to be able drive data from the editor.

Simple fix. Change it to 1 or 2 or whatever you want it to be in the inspector. If you don't want that variable to be editable in the inspector, you can make it private.

 private var levelNumber = 1;
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 Statement · Nov 07, 2015 at 10:58 PM 1
Share

http://docs.unity3d.com/$$anonymous$$anual/Inspector.html

Any property that is displayed in the Inspector can be directly modified. Even script variables can be changed without modifying the script itself. You can use the Inspector to change variables at runtime to experiment and find the magic gameplay for your game. In a script, if you define a public variable of an object type (like GameObject or Transform), you can drag and drop a GameObject or Prefab into the Inspector to make the assignment.

avatar image Pejovski Statement · Nov 07, 2015 at 11:36 PM 0
Share

Tnx for helping but i already solved this by my self like this

     $$anonymous$$ain$$anonymous$$enu.js Code:
     static var levelNumber = 1;
     function StartGameNew()
     {
         Application.LoadLevel(levelNumber);
     }
     Game$$anonymous$$aster.js code:
     function LoadNextLevel ()
     {
         finalScore = currentScore;
         $$anonymous$$ain$$anonymous$$enu.levelNumber++;
         if($$anonymous$$ain$$anonymous$$enu.levelNumber == 9)
         {
             $$anonymous$$ain$$anonymous$$enu.levelNumber = 1;
         }
         Application.LoadLevel ("EndLevel"); 
     }

so its like this when player loses calls LoadNextLevel() function and goes to EndlLevel(scene) and in that scene i have button with function StartGameNew() from $$anonymous$$ain$$anonymous$$enu.js

avatar image
0

Answer by feliperapussi · Nov 07, 2015 at 07:05 PM

this error is because you do not put the scenes in the build settings you have to go to File> Build Settings , and grovellest all his scenes in it and position correctly in the first place the main menu, then the scene 1,2,3 ... and finally the End

try it , you'll probably show up another error then why not make sense to me that this wanting to do this code

Comment
Add comment · Show 1 · 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 Pejovski · Nov 07, 2015 at 10:39 PM 0
Share

i know that and i have added them but smth other is the problem, btw my level's names are like htis Level01 Level02 so i want to go open them in order so i think this is good Application.LoadLevel("Level0" + levelNumber); and its working but somehow ins$$anonymous$$d Level01-8 its loading first Level01 then tries Level00 and i dont have Level00 and i dont know how it gets to Level00 my code is made to go from 1 to 8 not 0..

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

34 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

Related Questions

Setting objects that are large-scaled to static causing Unity to be stuck in '5/11 Clustering' 0 Answers

Simple - Save and Loading Scene 0 Answers

Game works fine inside editor but takes forever to load after build. 0 Answers

Light isn't loading 0 Answers

How Would I Load A Level From A Gui Button Press 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