Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Score Tally (kick my arse...)

$
0
0
sigh. Getting the scores to tally up is really kick my ass, guys.. I have it working throughout the game, but at the end of the game, when I want things to tally up, things don't work. Here is the part of my code that works. It is of the points accrued throughout the level: static var coinCollect = 0; static var scoreCurrent = 0; static var lifeTotal = 10; static var myTimer = 500.0; static var myCurScore = 0; //linked to Destroy_1sec Script (shown at the bottom of my post) function OnGUI () { //variables var scoreCount = scoreCurrent.ToString(); var coinCount = coinCollect.ToString(); var lifeCount = lifeTotal.ToString(); var timeCount = Mathf.Ceil(myTimer).ToString(); GUI.skin.button.wordWrap = true; if(scoreCurrent < myCurScore){ scoreCurrent+=4; } the myCurScore is linked to a destroy script where the player earns a coin. No here's where it gets tricky. I have these values created throughout the gaming experience. It's very easy to be like, "Ok, so a coin is worth 100 points. so let me make the script that if 100 points are collected the tally that into the current score until +100 is hit." but the variable of what the player collects throughout the level is not as simple. They can get 500 in coin points, or 2500. Who knows. So the part of my script that isn't working is here: function LevelComplete(){ var totalScore: int = myCurScore + (coinCollect * 10) + (myTimer * 2); var scoreCount = totalScore.ToString(); GUI.Label (Rect (Screen.width/1.2 + 20, 10, 80, 50), scoreCount, fontGUI); } In this case, I want the totalScore to show at the end of the level. Which it does, but the numbers climbing to that final figure don't show. it goes straight from 0 to 100 (or whatever). I want it to go from 0 to 1, 2, 3, 4, etc. Using: "if(scoreCurrent < myCurScore){ scoreCurrent+=4; }" As an example, how would I implement that into my Level Complete script so that the totals of whatever other score additives I make get tallied into the level's final score in an incremental way--instead of just immediately showing the full number. This is purely for aesthetic reasons, because it's nice to watch a number climb. Thanks for any help/suggestions. This stuff makes my head spin. HERE IS THE DESTROY 1 SEC SCRIPT: private var done = false; function Start () { } function Update () { if(!done){ GUIWorld.coinCollect += 1; GUIWorld.myCurScore += 100; Destroy(gameObject, 0.8); done = true; } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles