How do I make my game change levels after collecting all objects?

I am very new to unity and I am having trouble with getting my game to change levels after I have collected all objects.
I currently have a working main menu with buttons that allow me to exit and my first scene with an object collect system that displays score in the top right of my screen. `

// JavaScript
var score = 0;

function OnTriggerEnter( other : Collider ) {
Debug.Log(“OnTriggerEnter() was called”);
if (other.tag == “coin”)
{
Debug.Log(“Other object is a coin”);
score += 1;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}

function OnGUI()
{
GUILayout.Label( "Score = " + score );

}`

This code works perfectly for collecting the objects and counting score and this is what I am using to keep count.

I am wondering if anybody can help me work out a way so that when my score reaches a certain point, e.g… 3 points, my game will progress to the next level where I could create a more challenging terrain and harder to find collectables.

Any feedback is appreciated.
Thanks

Hi,

I have two ways you may consider.

One is using Lerp which help you to change between multiple game object position and this is the way I use in most of my 2D games to change my screen (for example: from main menu to exit menu,…). For your case, this could be used to change between two objects which hold two different levels. However this needs a bit of practise to get over it well. But if you could, this would definitely your best tool.

The second way, which I may recommend for beginner like you because it’s what I think the easiest way is using “LoadLevel” which load another scene and in this case, load another level. I don’t know how it’s exactly written in JS (because I don’t use it) but what here in CS:

//Your above code

//Put these lines of code in Update function

//You have to make a scene called “level2” or whatever you may want and put exactly in the quotation mark

if (score >= 3) {
    Application.LoadLevel("level2");}

Sorry for my bad English. Feel free to ask further if you don’t understand at any part. This is the first time I answer someone so may get the answer confusing