- Home /
check if an always increasing variable has stop increasing
float distance is always increasing, when it stop by a not really that important factor. i want to check it.
That is quite unclear situation,
"when it stop by a not really that important factor. i want to check it."
is that not so important factor applied or are we talking about slowing down rigidbody? If it is applied then you have a method somewhere, use that method to inform the scripts in need.
Answer by Eno-Khaon · Aug 21, 2015 at 08:00 AM
Generally, the easiest way to compare is to maintain a second variable with the value at the previous point of reference.
// C#
float lastValue;
float currentValue;
void Update()
{
currentValue = valueToMaintain; // Whatever value you might be holding
if(lastValue == currentValue)
{
// The value didn't change in the last frame
}
lastValue = currentValue;
}
That should use an approximation. It is highly likely that the comparison will never work.
1.0000000000001 is not 1.0000000000000 for a computer.
Answer by GiyomuGames · Aug 21, 2015 at 05:23 AM
Can't you just store its value from 1 update to another, and check if the new value is bigger or not?