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 shepsaus000 · Jan 14, 2016 at 04:21 PM · scripting problem

Scene/Level changing problems

So I've been looking at some tutorials to figure out how to change levels/scenes in Unity. However, the tutorials were involving some older versions of Unity, not Unity 5.3. I've tried to figure out how to convert the information from the older API into the newer form, but I feel like that effort is futile. So, I'm here to ask the Unity community the following questions:

  1. Am I scripting for the change in level correctly?

  2. Why am I getting an error saying that on line 38, that there is an unexpected symbol "/", when it's expecting a "." If I am reading this correctly, it is referring to the first slash in the following line:

SceneManager.LoadScene(string /Volumes/...etc.);

I'm also going to provide my entire script to aid in your evaluation. Also, please bear in mind that this script is still a work in progress and there is nothing that is calling upon the "StartLevel" function yet. However, that shouldn't be a problem because my problem involves whether or not I'm actually writing the "StartLevel" function correctly

Also, before I provide my script, please let me know if you need more information:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class MenuScript : MonoBehaviour {
 
     public Canvas quitMenu;
     public Button startText;
     public Button exitText;
 
 
     void Start () {
         quitMenu = quitMenu.GetComponent<Canvas> ();
         startText = startText.GetComponent<Button> ();
         exitText = exitText.GetComponent<Button> ();
         quitMenu.enabled = false;
     }
 
 
     public void ExitPress()
     {
 
         quitMenu.enabled = true;
         startText.enabled = false;
         exitText.enabled = false;
 
     }
 
     public void NoPress()
     {
         quitMenu.enabled = false;
         startText.enabled = true;
         exitText.enabled = true;
     }
 
     public void StartLevel(){
         SceneManager.LoadScene(string /Volumes/...etc.);
     }
 
     public void ExitGame()
     {
         Application.Quit ();
     }
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by corn · Jan 14, 2016 at 05:06 PM

First of all, check the Scripting API page. That should be the first thing you do whenever you feel lost, because it is always up to date, unlike some tutorials.

As you know, line 38 is the issue :

 SceneManager.LoadScene(string /Volumes/...etc.);

string /Volumes/...etc. doesn't make any sense. I don't quite understand where you were going with that. However, you cannot use a / in a variable name. What you're actually doing there is declaring a string variable, but the variable name is incorrect, and even if it was, you cannot declare a variable when calling a function. Last but not least, even if you could, this string would not be initialized, so LoadScene would fail. So you really need to declare a string variable beforehand (and initialize it), then call LoadScene with this variable as a parameter.

There is two ways to load a scene with SceneManager.LoadScene : with the scene name, or with its index in the Build Settings. It is imperative that the scene is in the build settings (File > Build Settings > Add Current or drag and drop the scene you need) in order to be able to load it.

So let's just declare a string variable that will be our scene's name.

 public class MenuScript : MonoBehaviour {
   [SerializeField]
   string m_LevelName = string.Empty;
 
   ...
 }

That way, using SerializeField, you can change LevelName from the inspector, so there's no need to modify your script if you decide you want to load a different scene or if you change the scene's name.

Then, to load the scene :

 public void StartLevel() {
   SceneManager.LoadScene(m_LevelName);
 }

And that's it !

Comment
Add comment · Show 4 · 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 shepsaus000 · Jan 14, 2016 at 06:39 PM 0
Share

I thought that I had to put the scene's path as the parameter. I figured it would be wrong, but the knowledge I've been getting from several different forums, websites, and tutorials gave me the impression that it would work (I'm such a silly person :P).

Anyway, so I got that to work, but whenever I call upon this function, I get a new error saying that the scene could not be loaded because it hasn't been added to the build settings or the AssetBundle hasn't been loaded. I know what it was referring to as the build settings, so I added the scene there, but it's still giving me the error, so I'm assu$$anonymous$$g that the problem lies within this AssetBundle thing it referred to. I have no idea what that is though, so maybe you could shine some light on this.

avatar image corn shepsaus000 · Jan 14, 2016 at 06:53 PM 0
Share

What is the name of your scene, and what is the string you're calling LoadScene with ? Have you tried using LoadScene with the scene's index rather than its name ? Also please post the entire error message.

avatar image shepsaus000 corn · Jan 15, 2016 at 04:10 PM 0
Share

The name of my scene is $$anonymous$$ain Level. The string I'm calling LoadScene with is (I'm assu$$anonymous$$g you're referring to the string within the script):

 [SerializeField]
     string m_$$anonymous$$ainLevel = string.Empty;
 
 public void StartLevel(){
         Scene$$anonymous$$anager.LoadScene (m_$$anonymous$$ainLevel);
     }

In the inspector, I defined $$anonymous$$ain Level as the full path to the scene.

I can't post the entire error message, because it contains personal information, but I will definitely put down as much as I can:

Scene /Volumes/Groups...etc. (assume the entire scene's path has been put in) 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.

avatar image Graphics_Dev shepsaus000 · Jan 14, 2016 at 06:58 PM 0
Share

About assetbundles:

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

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

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

35 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

Related Questions

How to modify many prefab objects in a script?, 0 Answers

change game character/controller when inside box - RFPSP 1 Answer

Jitter when moving around a circular path 0 Answers

Auto exit script 2 Answers

How can I fix my jumping script? 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