- Home /
[SOLVED]cant load lvl and i cannot figure out why.
Hello, my problem is that in my script i have a sort of countdown GUI with floats, and i want to go to another scene when it reaches zero but for some reason it just doesnt go to the other scene, and they are both in my build settings
here is my script
"using UnityEngine; using System.Collections;
public class BatteryLife : MonoBehaviour { public float maxBattery = 100.0f; public float curBattery = 100.0f; public float batteryDrainSpeed = 500.0f; public string battery = "Battery: ";
void Start () {
}
void Update () {
curBattery = Mathf.Clamp(curBattery - (Time.deltaTime * (1000 / batteryDrainSpeed)),0.0f,maxBattery);
}
void OnGUI() {
GUI.Box(new Rect(140, 175, Screen.width / 10 /(maxBattery / curBattery), 25), battery + curBattery + "/" + maxBattery);
}
void Death(){
if(curBattery >= 0)
{
Application.LoadLevel("Death");
}
}
}"
i could realy use a unity magicians help. and ty
Answer by christoph_r · Jun 10, 2014 at 11:55 PM
It should be
if(curBattery <= 0)
.You need to call your
Death()
method somewhere for it to work, calling it inUpdate()
after assigning your new curBattery should do the trick.
WOW, thanks, i always seem to mess up the <> symbols and such, but again thanks
You're welcome! Feel free to accept answers as right so it doesn't float around as an unsolved question.
Your answer
Follow this Question
Related Questions
Input.GetMouseButton on multiple objects 1 Answer
Application.LoadLevel not working 1 Answer
Problem LoadLevel 1 Answer
how to load level when your enemy health gets to 0 1 Answer
Can you use a var to load a level? 2 Answers