A "Between" command.

Yes I know it's a stupid question but ever since I only know LUA I'm not so good with Java...

Is there a between command? Something like this;

Function Update () {

   if (eulerAngles "Between 10 and 175")
      eulerAngles = 10;
   if (eulerAngles "Between 350 and 175")
      eulerAngles = 350;
}

As you can see I want a maximum and minimum angle on my object. I this is what I came up with. If you have an other answer, piece of script, please give it to me. Although I would like to know a way to use some kind of between command.

Oh and, please only post a script of which you are certain that it will work. I asked similar questions like this one before but I didn't get a straight or working answer out of one of those. So I just ask again.

You never just ask people to make your own scripts. That's just rude.

I'm a bit confused. You said you want a min/max limit. The possible numbers are: (-infinity)-10 and 350-(infinity). Is that what you want?

3 Answers

3

Mathf.Clamp is your friend!

For your particular example, Mathf.Min/Clamp will do the job.

As for the 'between' thing, it's just a matter of combining very simple tests:

if (eulerAngles >= 10 && eulerAngles <= 175)
      eulerAngles = 10;
if (eulerAngles >= 175 && eulerAngles <= 350)
      eulerAngles = 350;

Does this work?

eulerAngles is of type Vector3 and the reference says it is better to set them all at once:

transform.eulerAngles = Vector3(xRotation, yRotation, zRotation);

You should post this as a comment or a new question instead of as an answer.