- Home /
Three Possible Conditions, Checked in Update, Print Condition Only On Condition Change
I know that title was a mouthful. I am using a terrain gradient script, and in order to ensure that it is working correctly I am logging out whether the character is going uphill, downhill, or on flat terrain, during update, but doing so logs that same message over and over. What I want is for it to log only once on gradient change.
Normally you would use a bool and this would be pretty simple, but my problem here is that there are three conditions, and they are each met by a range of values, which is complicating things for me.
Here's what I've tried that isn't working:
bool GradientChange = true;
if (angle > steepGradient)
{
if(GradientChange == false)
{
Debug.Log("going uphill");
GradientChange = true;
}
}
else if( angle < -steepGradient)
{
if (GradientChange)
{
Debug.Log("going downhill");
GradientChange = false;
}
}
else
{
if (GradientChange == false)
{
Debug.Log("on roughly flat terrain");
GradientChange = true;
}
}
Your answer
Follow this Question
Related Questions
Update collisions 1 Answer
Only once in update 1 Answer
Keyboard Input Question 1 Answer
Access a variable from another script in update function 1 Answer
Most efficient way of pausing a function 0 Answers