• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MgBag · Mar 14, 2011 at 01:35 PM · between

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image taoa · Mar 14, 2011 at 05:31 PM 1
Share

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

avatar image Bunny83 · Mar 14, 2011 at 06:41 PM 0
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by taoa · Mar 14, 2011 at 02:20 PM

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;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Jake-L · Mar 14, 2011 at 01:54 PM

Mathf.Clamp is your friend!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by efge · Mar 14, 2011 at 02:33 PM

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);
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TowerOfBricks · Mar 14, 2011 at 06:20 PM 0
Share

You should post this as a comment or a new question ins$$anonymous$$d of as an answer.

avatar image Bunny83 · Mar 14, 2011 at 06:31 PM 0
Share

He don't used transform.eulerAngles. I guess he just created his own variable called eulerAngles. The name would be of course a bit confusing because if it's a single float the "s" at the end doesn't make much sense. If he really want's to access transform.eulerAngles that way it won't work. Oh and the reference suggested to not change eulerAngles directly at all. If you change one component or all doesn't change much. If you change it manually you have to take care about that you stay inside [0,360] or it will throw an exception. To setup a rotation with eulerangles use Quaternion.Euler

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

switch player and npc follow player 0 Answers

How do I remove these transparent lines between my tiles? 1 Answer

How to check if X Coordinate 1 > X Coordinate 2 1 Answer

make colliders between 2 objects. 0 Answers

Using classes between scripts in C#? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges