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 /
This question was closed Sep 28, 2014 at 12:05 PM by Bunny83 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by KakeGamer · Sep 27, 2014 at 09:13 PM · scene-loadingloadlevel

[Solved]Application.LoadLevel("Scene"); not working!

The scenes simply dont change Here is my code:

using UnityEngine; using System.Collections;

public class LevelController : MonoBehaviour {

 public static LevelController instance;

 public int xpMultiply = 1;
 public float xpFirstLevel = 100;
 public float difficultyFactor = 1.5f;


 // Use this for initialization
 void Start () {
     Application.LoadLevel ("1");
     instance = this;
     DontDestroyOnLoad (gameObject);

 }
 


 
 // Update is called once per frame
 void Update () {
     if (Input.GetKeyDown (KeyCode.A))
         AddXp (100);
     if (Input.GetKeyDown (KeyCode.R))
         PlayerPrefs.DeleteAll();
 
 }
 public static float GetCurrentXp() {
     return PlayerPrefs.GetFloat ("currentXp");
 }


 public static void AddXp(float xpAdd) {
     float newXp = (GetCurrentXp() + xpAdd)*LevelController.instance.xpMultiply;
     if (newXp >= GetNextXp()) {
         AddLevel ();
         newXp = 0;
     }
     PlayerPrefs.SetFloat ("currentXp", newXp);
 }
 public static int GetCurrentLevel() {

     return PlayerPrefs.GetInt ("currentLevel");
 
 }
 public static void AddLevel() {
     int newLevel = GetCurrentLevel() + 1;    
     PlayerPrefs.SetInt ("currentLevel", newLevel);
 
 }
 void OnGUI(){
     GUI.Label (new Rect(0, 0, 200, 50), "Current XP = " + GetCurrentXp());
     GUI.Label (new Rect(0, 70, 200, 50), "Current XP = " + GetCurrentLevel());
     GUI.Label (new Rect(0, 140, 200, 50), "Current Next Xp = " + GetNextXp());

} public static float GetNextXp() { return LevelController.instance.xpFirstLevel GetCurrentLevel()+1 LevelController.instance.difficultyFactor;; }

}

Comment
Add comment · Show 2
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 JamesL98 · Sep 27, 2014 at 09:50 PM 0
Share

Do You Get Any Compilor Errors?

avatar image KakeGamer · Sep 27, 2014 at 10:32 PM 0
Share

I solved the problem! I forget to put the PlayerStatsController Object in the Loader scene :( Thank You for the attention!

2 Replies

  • Sort: 
avatar image
1

Answer by smnerat · Sep 27, 2014 at 09:39 PM

If your levels have been assigned in the build settings, then I'm pretty sure you just need to get rid of the parenthesis around 1.

 Application.Loadlevel(1);
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 KakeGamer · Sep 27, 2014 at 10:33 PM 0
Share

I solve the problem! I forget to put the PlayerStatsController Object in the Loader scene :( Thank You for the attention!

avatar image
0

Answer by Bunny83 · Sep 27, 2014 at 09:43 PM

Are you sure that you have added your desired level to the build list and that your level is actually named "1"? Maybe you want to use an index instead of a level name. In that case don't use a string but an integer value.

If you have all your levels / scenes added to that list, do you get any error in the console? "not working" doesn't really help to understand your problem...

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 KakeGamer · Sep 27, 2014 at 10:33 PM 0
Share

I solve the problem! I forget to put the PlayerStatsController Object in the Loader scene :( Thank You for the attention!

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you move to a next scene directly when a video stops playing? 4 Answers

Scenes not loading on web player 2 Answers

LoadLevel Doesn't have script 1 Answer

How to prevent a script from running until the scene is loaded? 2 Answers

How to keep certain information when reloading a level 8 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