Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ItsKhanny · Jun 17, 2015 at 07:02 PM · c#

Change level script

I have a script I used all the time in Unity 4 and now I think Unity 5 has changed some stuff to where the script wont work. I am also gonna ask is there a way to where I can set it to where all I have to do is put the script on a trigger then the scene so I don't need to make so many scripts?

Script: C#

 using UnityEngine;
 using System.Collections;
 
 public class L12L2 : MonoBehaviour {
     
     void changesceneto() {
         Application.LoadLevel (2);
     
     }
 }

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
1
Best Answer

Answer by hnmikechan · Jun 27, 2015 at 01:55 AM

You're command is correct, you just need to make sure all your scenes are setup correctly in the build settings: Application.LoadLevel(2);

You don't need to make a new script for each Application.LoadLevel();

in a single script you could have multiple methods loading different levels;

 public void goToSceneOne(){
 Application.LoadLevel(1);
 }
 
 public void goToSceneTwo(){
 Application.LoadLevel(2);
 }

or else you could pass an int value:

 public void switchScene(int i){
 Application.LoadLevel(i);
 }
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 ItsKhanny · Jun 27, 2015 at 02:12 AM 1
Share

I am seriously dumb, i forgot to add the scene to the build. I am face pal$$anonymous$$g so hard right now here is a picture of how hard. alt text

download.jpg (4.8 kB)
avatar image hnmikechan · Jun 30, 2015 at 06:55 PM 0
Share

Should probably accept one of the answers that recommended this fix ;)

avatar image
1

Answer by lloladin · Jun 23, 2015 at 11:38 AM

youre load lvl seems to be correct did you remember to add the scene to youre build? and to avoid making so many scripts you could make

 Public String LevelToLoad = "Level1";
     

and then use the string inside youre

 Application.LoadLevel (LevelToLoad);

just change the Strings text per scene

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 ItsKhanny · Jun 26, 2015 at 09:58 PM 0
Share

I've ended up adding that and it says namespaces could only contain types and namespace declarations

here it is using UnityEngine; using System.Collections;

 public string levelToLoad = "Level1";
 
 
 public class LevelChange : $$anonymous$$onoBehaviour {    
     void update() {
         Application.LoadLevel (levelToLoad);
         
     }
 }
avatar image Hellium · Jun 26, 2015 at 10:02 PM 0
Share

First of all, you are trying to call Application.LoadLevel (levelToLoad); in the Update function = very, very, very bad idea

Put public string levelToLoad = "Level1"; inside your class

avatar image ItsKhanny · Jun 27, 2015 at 01:45 AM 0
Share

It says that Level1 is not being used in context

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Convert line of Csharp to Javascript 1 Answer

I cannot figure out what my error is... 2 Answers

Working with interfaces, best practices? 1 Answer

Button not executing function. C# 3 Answers

calling c# method from different c# file 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