- Home /
Adding tools with respect to points
How would I have there be a counter to add totls without it continuously adding instead of stopping once the points are added from the last run
using UnityEngine; using System.Collections;
public class playerprofile : MonoBehaviour {
public static int TotalScore = 0;
public static int TotalShots= 0;
public static int TotalEnemies = 0;
private int buttonWidth = 200;
private int buttonHeight = 50;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
TotalScore = player.Score + TotalScore;
TotalShots = player.ShotsFired + TotalShots;
TotalEnemies = player.EnemiesMissed + TotalEnemies;
}
void OnGUI()
{
BuildUI();
}
void BuildUI()
{
GUI.Label(new Rect(10, 10, 1200, 20), "Total Score: " + TotalScore.ToString());
GUI.Label(new Rect(10, 30, 1200, 20), "High Score: " + player.HighScore.ToString());
GUI.Label(new Rect(10, 50, 1200, 20), "Total Shots Fired: " + TotalShots.ToString());
GUI.Label(new Rect(10, 70, 1200, 20), "Total Enemies Killed: " + TotalEnemies.ToString());
}
What? Your question sounds like a double negative and contradicts itself. Could you please rephrase?
Answer by rockyourteeth · Mar 19, 2014 at 08:41 PM
Whatever is in "player.score" is going to get added to your total score EVERY frame (many times per second), because it's in the "update()" function. Are you sure you don't want to move:
TotalScore = player.Score + TotalScore;
into the "start()" function, to happen only once at the beginning of a level, or whatever?
Thank you I did realize this and now its in start and works with no bugs at this poin, I didnt think of it till after I had someone in my class look at it
Thanks. $$anonymous$$ark as correct answer, thanks ;)
Your answer
Follow this Question
Related Questions
Adding submeshes seems to multiply the vertex and triangle count in render stats? 0 Answers
Stats Window shows Render Textures in Unity Free 1 Answer
Can I use Scriptable Objects for Hero Stats that change throughout the game? 0 Answers
texture to an object 2 Answers
Adding to an array - C# 2 Answers