Loading a new level based on score

I would like to load a new level when the playerScore reaches 20. I’ve been using if statements followed by load level but they’re not working. Could someone take a look at the script and tell me what I should be doing?

Blockquote
var cSpeed:float = 10.0;
var sFactor:float = 10.0;
//Two variables to hold our scores
static var playerScore:int = 0;
static var enemyScore:int = 0;

function Start ()
{
rigidbody.AddForce(10,1.5,0);
}

function Update ()
{
var cvel = rigidbody.velocity;
var tvel = cvel.normalized * cSpeed;
rigidbody.velocity = Vector3.Lerp(cvel,tvel,Time.deltaTime * sFactor);

//Check the right bounds
if(transform.position.x > 24)
{
playerScore++;
transform.position.x = 0;
transform.position.y = 0;
}
//Check the left bounds
if(transform.position.x < -24)
{
enemyScore++;
transform.position.x = 0;
transform.position.y = 0;
}
}

if(playerScore <= 20){
Application.LoadLevel(“level2”);
}

OR

if(playerScore <= 20){
Application.LoadLevel(2);
}

Also see: Application

So you definitely have the right idea. The only thing is to make sure that you have the levels loaded into the build settings. To do this if you haven’t already File->Build Settings then ensure that all levels are added.

There are two ways to load a level. One by index and the other by string as you just provided. Obviously make sure that the string matches 100% otherwise it will not load. So in your case…

if(playerScore <= 20){
Application.LoadLevel("Medium Mode");
}