- Home /
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;
}
}
An example of how you were calling Application.LoadLevel() would be helpful as there is no instance in your example. =)
Sorry, my point was that I don't really know how to go about doing that. I was basically just making stuff up and hoping it would work. the level is called "$$anonymous$$edium $$anonymous$$ode" though
Answer by Stormizin · Oct 30, 2013 at 04:22 PM
if(playerScore <= 20){
Application.LoadLevel("level2");
}
OR
if(playerScore <= 20){
Application.LoadLevel(2);
}
Also see: Application
Thanks guys! That's what I was doing, but I keep getting this message: $$anonymous$$ identifier: 'playerScore' But I know that's what the static var is.
If any answer helped you please mark it to an answer of this question to keep the community organized.
I will, just nothing has worked yet and I can't figure out why
Answer by Deathdefy · Oct 30, 2013 at 04:27 PM
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");
}
Your answer
Follow this Question
Related Questions
How to move a object side to side using mouse? js3 0 Answers
How to freeze movement on X-axis. (See Comments for Update) 2 Answers
Master Server and Faciliator connection 0 Answers
Unity pong online multiplayer 0 Answers
Can you help me with my loading screen 0 Answers