I’ve been working on a simple upgrade system where the player has to collect 100 coins, and every time a hundred is collected, the player’s health is upgraded. I have tried many, many ways to save the maxHealth var using playerprefs. Maybe someone has an answer for me, that would be much appreciated.
Here is some snippets of the Health script:
var curHealth = 3;
static var coins = 0;
static var maxHealth = 3;
coins = PlayerPrefs.GetInt("Coin");
function Start(){
curHealth = maxHealth;
}
function FixedUpdate(){
if(curHealth <= 0){
Application.LoadLevel(Application.loadedLevel);
}
if(coins == 100){
maxHealth ++;
curHealth = maxHealth;
coins = 0;
}
if(maxHealth > 10){
maxHealth = 10;
curHealth = maxHealth;
}
}
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "Health"){
Destroy(other.gameObject);
curHealth = maxHealth;
}
if(other.gameObject.tag == "Coin"){
coins ++;
Destroy(other.gameObject);
PlayerPrefs.SetInt("Coin",coins);
}
}