How to check if a variable has gone up or down

Hi,

I’m trying to rotate my camera based off of a variable “gravityState” and I have no idea what to put in the brackets of the if statement to recognise this variable going up or down by 1.

The following is my code so far for when the variable “gravityState” goes up by 1.

 if ( //required statement //)
        {
            Vector3 to = new Vector3(0, 0, 90);
            if (Vector3.Distance(transform.eulerAngles, to) > 0.01f)
            {
                transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime*5);
            }
            else
            {
                transform.eulerAngles = to;
                
            }
        }

Also, in my testing for when the variable goes down I found that when changing “90” in line 3 of the code to “-90” the camera would spin forever, does anyone know why?

Any help is appreciated.

It’s hard to answer if you don’t provide the code related to the gravityState variable…

I would advise you to use properties as follow :

private float gravityState ;

public float GravityState
{
    get { return gravityState ; }
    set
    {
        GravityIncreasing = value >= gravityState;
        gravityState = value ;
    }
}

public bool GravityIncreasing = false ;

Then, in your code, use the property as follow (mind the capital letter). Don’t use the private float;

GravityState = -9.1f ;
// ...
GravityState = -5f ;

// ...
if ( GravityIncreasing )
{
       // Your code
}