How does this variable equal two different values
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;
}
}
the alternate doesn't make sense from what you've posted, there must be something missing
Answer by Jdzeke · Feb 11, 2017 at 01:20 AM
I found my error. I accidentally had this script running on two different game objects. Thanks for the help anyway
Your answer
Follow this Question
Related Questions
Power up button 0 Answers
Unwanted behavior when manipulating a public integer from a different script: How can it be fixed? 1 Answer
Is there an int based class/struct like Vector2? 4 Answers
create graph editior for values 0 Answers
How to change the variables in my argument through a function? 2 Answers