Search Unity

Loading next level

Discussion in 'Getting Started' started by KarBis, Nov 1, 2019.

  1. KarBis

    KarBis

    Joined:
    Sep 6, 2019
    Posts:
    25
    Hi guys,

    I'm trying to load the new level once the score equals 100.
    I wrote this script, but nothing is happening once I reach 100, could you advise?


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7.   public Text scoreText;
    8.  
    9.     private int score;
    10.  
    11.     void Start()
    12.     {
    13.         score = 0;
    14.         UpdateScore();
    15.     }
    16. public void PlayNextLevel ()
    17.     {
    18.        
    19.      if (score >= 100)
    20.      {
    21.         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    22.     }
    23.     }
    24. }
    25.  
     
  2. Do you call the PlayNextLevel method from anywhere? Because you only have an "UpdateScore" called and only from the Start method.
     
  3. KarBis

    KarBis

    Joined:
    Sep 6, 2019
    Posts:
    25
    I'm so stupid!

    Thank you, it's fixed now