In the console when I say Debug.Log(points), is says that the the variable “points” is equal to two numbers. It starts out fine and displays the number 0, and counts up every few seconds like it’s supposed to, but after I run the function SubtractPoints() by clicking a button, the points don’t get any lower. It alternates between showing the number that doesn’t get lower and a new number that does get lower. This is a picture of the console after clicking the button once.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class initialization : MonoBehaviour {
float points;
//The rate that points are given to the player
float pointCounterRate;
//The time at the last point given
float lastPoint;
// Use this for initialization
void Start()
{
points = 0f;
pointCounterRate = 3.0f;
lastPoint = 0.0f;
}
// Update is called once per frame
void Update ()
{
if (Time.time > pointCounterRate + lastPoint)
{
lastPoint = Time.time;
points ++;
}
Debug.Log(points);
}
public void SubtractPoints()
{
points -= 5;
}
}