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 /
This question was closed Jan 30, 2016 at 10:21 PM by BrodyDaChappy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by BrodyDaChappy · Jan 30, 2016 at 07:57 PM · scorelevelload

Help to Stop Level Load Loop

Hi All,

I have just recently added to my level manager script so that once max level points are achieved on level_1 load level_2 and continue points to level_2 from level_1.

The problem is that when level_2 loads the points are shown from Level_1 but the level wont play, i know that the level is continuously loading but i am stuck on how i can stop it loading so i can play the next level?

my script is:

using System.Collections;

public class LevelManager : MonoBehaviour {

 public LevelManager levelManager;
 public int score;
 public int Score=30;
 

 private PlayerController player;

 // Use this for initialization
 void Start () {
     player = FindObjectOfType<PlayerController>();
     if (Application.loadedLevelName == "Level_1") {
         score = 0;
         saveScores();
     } else {
         score = getSavedScores();    
     }  

 }

// Update is called once per frame void Update ()

 {  
     
     saveScores();
     changeLevel();
 }
 
 public void changeLevel()
 {
     if (score >= 750)
     {

         saveScores();
         Application.LoadLevel("Level_2");  // save score before level loads & loads level
 
     }    
     if(Application.loadedLevelName == "Level_2")  //recognized the name of the level loaded & access score
     {
         getSavedScores();    
     }
     
 }
 //possible if the save functionality intreacts with this
 public void saveScores()
 {
     if (score >= 750)
     {
         // setting the score
         PlayerPrefs.SetInt("Score", score);
         
     }
 }
 public int getSavedScores()
 {
     
     int tempScore = PlayerPrefs.GetInt("Score");  
     
     return tempScore;
 }
 
 
 public  int getScore()
 {    
     
     
     return score;
 }
 public void AddPoints(int points)
 {
     score += points;
 }

 void OnGUI()
 {
     GUILayout.Label(score.ToString());
 }

 void OnTriggerEnter2D(Collider2D other)
 {
     if(other.name == "Player")    
     
     {
         Application.LoadLevel(0); //this is on death completely restart game
     }


 }

}

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

  • Sort: 
avatar image
0

Answer by BrodyDaChappy · Jan 30, 2016 at 09:13 PM

Anyone? i have tried as far as my knowledge of C# goes.

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 aferlane · Jan 30, 2016 at 09:50 PM

Try tracking the level that you're on as well, something along the lines of this:

 public void changeLevel()
  {
      if (score >= 750 && currentLevel == 1)
      {
          saveScores();
          currentLevel++;
          Application.LoadLevel("Level_2");  // save score before level loads & loads level
  
      }    


I'm not the greatest scripter, so might need to make some adjustments, but that general idea should help you out.

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 BrodyDaChappy · Jan 30, 2016 at 10:01 PM 0
Share

Thanks Aferlane,

That worked, but i have noticed that when i gain more points in level 2 it still loads level_2, even though i have said if score >= 750 load level 2, so once i gain more points it should stop the load level.

Any ideas?

Follow this Question

Answers Answers and Comments

41 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

Related Questions

Level Unlock System....frustrated,Building a level unlock system using player prefs 0 Answers

Unity/C# Respawn and score Problem 1 Answer

Highscore with Dreamlo 3 Answers

How do I add extra points for coming close to obstacle but NOT for coming close and colliding? 1 Answer

random occuring NullReferenceException 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