Check whether an object is rotating on the y axis, and if it does for an animation to play

I’m basically trying to determine whether an object is rotating on the y axis, and if it does for an animation to play.
Hi, I’ve looked around the forums and tried to apply different syntaxes and solutions to similar problems but nothing has worked.

The y axis starts of at a float of around -0.265

public class IsRotating : MonoBehaviour {
    public GameObject Pilot;
    public float more = -0.26f;
    public float less = -0.27f;

    //Vector3 oldEulerAngles;

    void Start()
    {
    }

    void Update()
    {
        if (transform.rotation.eulerAngles.y > less || < more)
        {
      
            Pilot.GetComponent<Animation>().Play("PilotTwo");
      
        }
    }
  
   
}

I think your code should look like this:

if( (transform.rotation.eulerAngles.y > less ) || (transform.rotation.eulerAngles.y < more ) )
{

}
1 Like