- Home /
This question was
closed May 23, 2014 at 06:26 AM by
Fattie for the following reason:
Duplicate Question
Score board acting funny
The score board has a 0 on top of the first number. 100 would be 000 (but with the one behind the first 0) (there is another script for right answers too, having the same problem ) using UnityEngine; using System.Collections;
public class scorno : MonoBehaviour {
//var outher = Collider
float playerwrong = 0;
void OnTriggerEnter( Collider no){
playerwrong += 1;
}
// Update is called once per frame
void Update ()
{
}
//Method to increase score though other scripts:
//Like collectibles, etc.
public void Increasewrong(int amount)
{
playerwrong += amount;
}
void OnDisable()
{
//Look to store somewhere else. Like a packet to persist with dont destroy on load.
PlayerPrefs.SetInt ("Wrong :(", (int)(playerwrong*100));
}
void OnGUI()
{
GUI.Label (new Rect (10, -5, 100, 30), "WRONG :(" + (int)(playerwrong * 100));
}
}
`
Comment
What??? Sir, 0*100 = 0. When you multiply a number by 0 you get 0.
Best Answer
Answer by joedartjr · May 23, 2014 at 01:13 AM
public class scorno : MonoBehaviour
{
//change the float to an int
int playerwrong;
void Start()
{
//if you want to set the value to the previous value when the script runs, if not omit this
playerwrong = PlayerPrefs.GetInt("Wrong");
}
void OnTriggerEnter( Collider no)
{
playerwrong += 1;
}
void Update ()
{
}
public void Increasewrong(int amount)
{
playerwrong += amount;
}
void OnDisable()
{
//change this so that the SetInt variable is properly called
PlayerPrefs.SetInt("Wrong", playerwrong * 100);
}
void OnGUI()
{
GUI.Label (new Rect (10, -5, 100, 30), "WRONG: " + playerwrong * 100);
}
}
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Displaying Score on screen 2 Answers
How To Stop Destroyer From Destroying? 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Guitext for score over time. 2 Answers