Hey all, I’m having some problems with my maths.
Here’s the code, pretty straight forward. This is probably one of those facepalm moments
var Lives : float = 3;
function Start() {
PlayerPrefs.SetFloat("Lives",Lives);
}
function OnTriggerEnter (other : Collider) {
if(other.tag == "Finish"){
MinusLives ();
Destroy(other.gameObject);
}
}
function MinusLives () {
Lives = PlayerPrefs.GetFloat("Lives");
Lives = Lives - 1; //I've also tried "Lives -= 1" here
PlayerPrefs.SetFloat("Lives",Lives);
}
function OnGUI () {
GUI.Box (new Rect ((Screen.width / 2), 5, 100, 20), "Lives: " +Lives);
}
My problem is: the number of lives isnt going down from 3 to 2, but from 3 to -1, and then will decrease normally.
Any help? I really don’t know why it’s doing this
Thanks in advance, Geko_X
PS: I’ve also tried using ints instead of floats.