- Home /
Question by
Seyed_Morteza_Kamaly · Dec 11, 2015 at 12:34 PM ·
unity 5
How can i initialize number when i use from playerprefs for saving my variables?
when i start my game initialize do not load because Health =GetInt("HealthSave"); that i have to define a boolean for reset. for example i want sell my product>>if i forget to use boolean for Reset GetInt("HealthSave"); my product will load "HealthSave" variable.
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public bool Reset = false;
public int Health = 3;
void Start(){
Health = PlayerPrefs.GetInt("HealthSave");
}
void Update(){
if (Reset == true) {
PlayerPrefs.SetInt("HealthSave", 3);
}
if (Health < 0) {
Application.LoadLevel ("gameover");
}
}
// Use this for initialization
void OnCollisionEnter(Collision theCollision){
if(theCollision.gameObject.name == "Doshman"){
PlayerPrefs.SetInt("HealthSave", Health-=1);
Application.LoadLevel(Application.loadedLevel); //RESTART
}
}
}
Comment