How To Check If X Rotation Is Between Two Numbers??

I’m making a game where an animation would only play if the player’s x rotation is between 2 numbers. Something like this(JavaScript Please):

if (Player x rotation is between 0 and 180)
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        animation.playe("Vault");
    }
}

I know this isn’t how the x rotation would be, but that’s the kind of thing im looking on how to do. Does anyone know how to do this? (In JavaScript).

If the object is only rotating on the ‘y’ axis, you can use eulerAngles. Assuming the script is on the player, the code would look like:

if (transform.eulerAngles.y >= 0 && transform.eulerAngles <= 180) {
    // Do stuff
}

But this is not a general solution. It will fail to work in many situations outside the specific situation you outline here (only ‘y’ rotation between 0 and 180). A slightly better solution (that also can have issues) might be:

if (Vector3.Angle(transorm.forward, Vector3.forward) <= 90.0) {
    // Do stuff
}