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

Load next level after collecting all pickups - help!

Discussion in 'Scripting' started by kamil0417, Nov 6, 2015.

  1. kamil0417

    kamil0417

    Joined:
    Oct 13, 2015
    Posts:
    4
    Hi!
    I've got 2 scripts, one of them is "Pickup" script attached to my "pickup object" and the second one is "Score System" that shows current score. What I want to do is to load next level after player collect all of the pickups. Any suggestions??
    "Pickup" script:
    Code (JavaScript):
    1. var CoinSound: AudioClip;
    2.  
    3. function OnTriggerEnter (info : Collider)
    4. {
    5.     if (info.tag == "Player")
    6.     {
    7.         ScoreSystem.myScore += 1;
    8.         AudioSource.PlayClipAtPoint(CoinSound, transform.position);
    9.         Destroy(gameObject);
    10.  
    11.     }
    12.  
    13. }
    and "ScoreSystem" script:
    Code (JavaScript):
    1. static var myScore = 0;
    2. public var guiSkin : GUISkin;
    3.  
    4. function OnGUI()
    5. {
    6.     GUI.skin = guiSkin;
    7.     GUI.Label(Rect((Screen.width / 1.5) - 40,50, 200, 30), "Bomb Parts: " + myScore);
    8.  
    9. }
     
  2. rchmiel

    rchmiel

    Joined:
    Apr 5, 2015
    Posts:
    49
    Are you kidding? o_O
    Add to first script right after destroy object:
    Code (csharp):
    1. if(ScoreSystem.myScore == someScore)
    2. {
    3.    Application.LoadLevel("nextLevel"); // or add more detailed function
    4. }
     
    kamil0417 likes this.
  3. kamil0417

    kamil0417

    Joined:
    Oct 13, 2015
    Posts:
    4
    Damn I must be retarded that I could not figure it out.
    Thanks man!