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

Im Doing HighScore System To My Game And There Is Something Wrong In My Scripts

$
0
0
So Im Doing highScore System When Players Health Is 0 It Sets New highscore But There Is Problem That When Helath Is 0 Nothing Happens -------HealthScript-------- var curHealth : int = 100; function Start(){ } function OnGUI(){ GUI.Box(Rect(Screen.width*0.9,Screen.height*0.5,100,25), curHealth.ToString()); } function OnTriggerEnter (other : Collider) { if(other.gameObject.tag == "enemy") curHealth -= 10; } -------ScoreScript-------- #pragma strict var highScore: int = PlayerPrefs.GetInt("HighScore"); function Start(){ InvokeRepeating("EachSecond",1.0,1.0); } var Elkit : GameObject; var score: int = 0; var addscore = 7; var HighScore : int; function EachSecond() { score=score+addscore; } function OnGUI(){ GUI.Box(Rect(Screen.width*0.9,Screen.height*0.2,100,25), score.ToString()); var health : Health; health = Elkit.GetComponent("Health"); if(health.curHealth == 0 && score <= highScore) { PlayerPrefs.SetInt("HighScore",score); } } ---------HighScoreScript----------- #pragma strict var highScore: int = PlayerPrefs.GetInt("HighScore"); function Start () { } function OnGUI(){ GUI.Box(Rect(Screen.width*0.9,Screen.height*0.3,100,25), highScore.ToString()); }

Viewing all articles
Browse latest Browse all 1333

Trending Articles



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