Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by Essential · Feb 02, 2012 at 11:17 AM · variableoperator

How is this operator in a variable declaration?

Have noticed this line in one of the bundled Unity scripts. Am not familiar with the use of comparison operators when setting a variable. Can anyone explain what it means?

 movement.isMoving = Mathf.Abs (inputDirection) > 0.1;
Comment
Add comment
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

1 Reply

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

Answer by flamy · Feb 02, 2012 at 01:55 PM

movement.isMoving is a boolean variable, You are checking whether the value of input direction is more than 0.1 either in negative or positive...

basically Mathf.Abs(inputDirection)>0.1 is a condition so it will return either true or false to the variable isMoving. This is equal to

 if(Mathf.Abs (inputDirection) > 0.1)
 {
          movement.isMoving=true;
 }
 else
 {
          movement.isMoving=false;
 }


Aditional: Check ternary operator is more like a simple if else loop that could also be used during variable declaration, with a condition. eg: var x=(y<3?3:3); this will clamp the value to 3 if the value is 3 or more or you will get the value of y in x. Hope it is clear :)

Comment
Add comment · Show 4 · 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 BiG · Feb 02, 2012 at 02:02 PM 0
Share

Thanks for this answer, @flamy, I was curious too about this. Just a question: is it possible both in Unityscript and C#?

I ask because I've never seen this synthax.

avatar image flamy · Feb 02, 2012 at 02:07 PM 1
Share

yes it is in any language. it is not specific to unityscript or c#....

but prefer not to use it though, because it would make the code hard to read sometimes.

avatar image BiG · Feb 02, 2012 at 02:09 PM 0
Share

Understood...Thank you!

avatar image Essential · Feb 02, 2012 at 03:26 PM 0
Share

Cool. I had a feeling that could be it! Thanks

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to properly declare this variable 2 Answers

How do you clear a variable in the inspector? 4 Answers

variable doesn't change 1 Answer

Why the variable updates only twice? 1 Answer

How to delete a Variable in a script in game 1 Answer


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