How to set up a task that after completed sends you to next level?

I am fairly new with Unity, I just started using it about a week and a half ago. I used the TornadoTwins Worm Game tutorial and have been working on my own game, based on what I learned from them. My game involves the character collecting a certain number of crystals and I have it so that you can collect the crystals using this script:

var explosion : Transform;
static var crystal = 0;
static var point = 0;

function OnTriggerEnter( hit : Collider )
{
   if(hit.gameObject.tag == "wormy")
      {
      Destroy(gameObject);
      var explosion = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
      crystal += 1;
      point += 5000;
      }

}

The explosion variable is just for what happens after you collect one crystal. So how can I make it so that after you collect a certain number of crystals a Level Complete text appears with a next button under it. I only need to know how to make the text pop-up, not take you to the next level, I know how to do that. So, how do I make it happen?

  1. You need a set number of crystals to collect (allCrystals).

  2. You need another var for the crystals you collect (crystals).

    function OnTriggerEnter(other:Collider)
    {
    if(other.tag==“Crystal”) //You have it tagged as “wormy”
    {
    crystals++; //Add 1 to the crystal var
    Destroy(other.gameObject); //Destroy picked up crystal

         //Loads next level if all the crystal have been collected
         if(allCrystals==crystals)Application.LoadLevel("MyLevel");
     }
    

    }

For the pop-up text/button, you can use the GUI system: enable the GUI code when the necessary crystals have been collected, like this (let’s call this script LevelCompleted.js):

// draw the message "Level Completed" and the Next button in some image
// editor like Photoshop, and import both images to your project
var message: Texture2D; // drag the Level Completed image here
var button: Texture2D; // drag the Next button image here
var nCrystals = 0; // how many crystals you have
var neededCrystals = 10; // how many crystal enable the next level
var nextLevel: String; // define the next level name in the Inspector

function OnGUI(){
  if (nCrystals >= neededCrystals){
    GUI.DrawTexture(Rect((Screen.width-message.width)/2, 200, message.width, message.height), message);
    if (GUI.Button(Rect((Screen.width-button.width)/2, 400, button.width, button.height), button){
      // button Next pressed - load level:
      Application.LoadLevel(nextLevel);
    }
  }
}

You can attach this script to any scene object - usually the camera or some empty object created just to hold the game control scripts.

The crystal picking script may be attached to the crystals or to the player. Anyway, add this code to it:

var controlScript: LevelCompleted; // drag here the object that has the LevelCompleted script

function OnTriggerEnter(other: Collider){
  if (other.tag == "whateverTagYouReUsing"){
    controlScript.nCrystals++;
    ...