- Home /
Question by
Ryujose · Aug 22, 2014 at 10:14 PM ·
playerprefsapplication.loadlevellives
PlayerPrefs after 0 lives, want to load another scene.
I want to load another scene when player got kill when is > 0. I don't want to load on 0, I want to load when is played with 0 and is killed. I think the problema is in "Public void zeroVidas ()"
How can I do it? There's my script.
using UnityEngine;
using System.Collections;
public class VidaScript : MonoBehaviour {
//Interfaz Grafica Vida
public int vida = 0;
private static int vidasIniciales = 2;
private static int vidasActuales;
public GUIText LivesText;
//Prueba
static VidaScript ()
{
vidasActuales = PlayerPrefs.GetInt("lives", vidasIniciales);
}
public static int VidasActuales {
get { return vidasActuales; }
set {
vidasActuales = Mathf.Max (0, value); // Para que no de negativo.
PlayerPrefs.SetInt ("lives", vidasActuales);
}
}
void Start ()
{
vidasActuales = PlayerPrefs.GetInt("lives", vidasIniciales);
UpdateVida ();
}
public void Subtract (int newValueVida)
{
vida -= newValueVida;
UpdateVida ();
}
void UpdateVida ()
{
LivesText.text = "Lives: " + vidasActuales.ToString ();
}
public void drecrementoVidas ()
{
vidasActuales--;
PlayerPrefs.SetInt("lives", vidasActuales);
}
public void incrementoVidas ()
{
vidasActuales++;
PlayerPrefs.SetInt("lives", vidasActuales);
}
public void zeroVidas()
{
if (VidaScript.vidasActuales > 0)
Application.LoadLevel ("StartScene");
}
}
Thanks for the help!
Comment