if (variable is between two values)

Hello there, how can I make unity check if a variable is between two values, while using if?

float vartree1 = Random.value;
            if (vartree1 <= .33) {
                other.gameObject.GetComponent<SpriteRenderer> ().sprite = tree1;
            }
            else if (.33 < vartree1 <= .66) { //I'm struggling with this line.
                other.gameObject.GetComponent<SpriteRenderer> ().sprite = tree2;
            }
            else if (.66 < vartree1) {
                other.gameObject.GetComponent<SpriteRenderer> ().sprite = tree3;
            }

Thank you in advance!

else if (vartree1 <= .66)
…
else if (vartree1 > .66)

your vartree1 is already > .33 if it came to your else condition.

1 Like

.33f

you really should use the suffix to differentiate between the various floating point types.

@LeftyRighty
thank you, everything works now :slight_smile: