Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

[SOLVED] Same script (virtually) on two gameObjects. One saves to playerprefs, one doesn't

$
0
0
Ugh. Sorry I'm asking this. I have two gameobjects, boss characters. Each has (nearly) the same script attached, a health script. The one works perfectly, and saves the result of the battle to playerprefs, so that after you've defeated him, he's gone for good. But the other one... The results of the battle never save. He just reappears every time the game is started, and I don't get it. Clearly, I've done something wrong, can't see something, have bad syntax somewhere, I don't know. Am hoping fresh eyes might see what I'm missing, because I'm banging my head against the keyboard after spending hours on this. The two scripts are below, starting with the working one. God bless, and thanks. Sorry to ask such a stupid question. **Working Script** var Name = "Guardian"; var Exp = 150; static var GuardianHealth : int = 75; var GuardianKilled = 0; function Start(){ if(PlayerPrefs.GetInt("GuardianDead", 0) == 1){ //object.active = true; //object.enabled = true; TowerGateOpen.GateOpen = true; Destroy(gameObject); } } function OnTriggerEnter (other : Collider){ if (other.gameObject.name == "sword") { GuardianHealth = -10; } else { if (other.gameObject.name == "club") { GuardianHealth = -1; } if(GuardianHealth <= 0 ) if(GuardianKilled == 0 ) { GuardianHealth = 0; GuardianKilled = 1; audio.Play(); Playerhealth.curXp += Exp; Playermoney.curMoney += 350; TowerGateOpen.GateOpen = true; PlayerPrefs.SetInt("GuardianDead", 1); Debug.Log( Name + " is killed"); Destroy(gameObject); } } } **Script that won't save to playerprefs:** var Name = "Medamomo"; var Exp = 450; static var MedamomoHealth : int = 5; var MedamomoKilled = 0; function Start(){ if(PlayerPrefs.GetInt("MedadmomoKilled", 0) == 1){ //object.active = true; //object.enabled = true; MedamomoGateOpen.GateOpen = true; Destroy(gameObject); } } function OnTriggerEnter (other : Collider){ if (other.gameObject.name == "sword") { MedamomoHealth = -7; } else { if (other.gameObject.name == "club") { MedamomoHealth = -1; } if(MedamomoHealth <= 0 ) if(MedamomoKilled == 0 ) { MedamomoHealth = 0; MedamomoKilled = 1; //audio.Play(); Playerhealth.curXp += Exp; Playermoney.curMoney += 1550; PlayerPrefs.SetInt("MedamomoKilled", 1); Debug.Log( Name + " is killed"); MedamomoGateOpen.GateOpen = true; Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>