Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Changing level when certain score is reached

Discussion in 'Scripting' started by yobtar, Aug 23, 2015.

  1. yobtar

    yobtar

    Joined:
    Aug 12, 2015
    Posts:
    7
    Hey everyone I am having trouble getting the proper script in place that I can add to my game where I can put in what score is needed to reach the next level and put what level to change to it is by having variables.

    I attached my script and i cant get it to work.

    Score is the set to public and what my total score is. I believe this is correct.
    I am trying to add levels to the Survival Shooter Tutorial game if that helps as well.

    Thanks
     

    Attached Files:

  2. EETechnology

    EETechnology

    Joined:
    Aug 15, 2015
    Posts:
    185
    Your script has some errors.
    Try THis:
    Its untested but if you modify by your needs it should work just fine
    Code (CSharp):
    1. int myActualScore = 0;
    2. int nextLevelScore = 100;
    3. public string level = "Level1001";
    4. public void Update(){
    5.       if(//Some stuff){
    6.             myActualScore++;
    7.       }
    8.       if(myActualScore == nextLevelScore){
    9.            Application.LoadLevel(level);
    10.       }
    11. }
     
  3. yobtar

    yobtar

    Joined:
    Aug 12, 2015
    Posts:
    7
    Would I make a new script with this and add to the level or would I add this to my score manager script which is here.

    How I thought it would work is on each scene would have the script added with Variable Values so that I can progress through levels.

    Sorry I am really new at this thanks


    This is the ScoreManager that I did in the tutorial.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. namespace CompleteProject
    6. {
    7.     public class ScoreManager : MonoBehaviour
    8.     {
    9.         public static int score;        // The player's score.
    10.  
    11.  
    12.         Text text;                      // Reference to the Text component.
    13.  
    14.  
    15.         void Awake ()
    16.         {
    17.             // Set up the reference.
    18.             text = GetComponent <Text> ();
    19.  
    20.             // Reset the score.
    21.             score = 0;
    22.         }
    23.  
    24.  
    25.         void Update ()
    26.         {
    27.             // Set the displayed text to be the word "Score" followed by the score value.
    28.             text.text = "Score: " + score;
    29.         }
    30.     }
    31. }