Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by DorkNemesis · Jun 10, 2011 at 01:24 PM · inventoryoperator

If value is multiple of

Hey guys,

Quick programming / unity question.

I want to make an inventory with a 3x3 grid. The highlight starts at 0,0. If player presses right, the highlight moves to 1, 0 and now he's on the second slot of the inventory.

Now the thing is - if the player is on the third slot and he presses right, the highlight should not just to 4,0, but to 0, -1 (which is slot 4).

And the same thing should happen when the cursor is at 6, 9, 12, 15 - every time the cursor is at a multiple of 3.

Is there a clever way of doing this?

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
17
Best Answer

Answer by Mike 3 · Jun 10, 2011 at 01:26 PM

You can use the % operator to do it

 if (val % 3 == 0)
 {
     //val is a multiple of 3, or 0
 }
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 Bunny83 · Jun 10, 2011 at 02:07 PM 0
Share

yep, modulo is your friend ;)

avatar image Tom 17 · Jun 10, 2011 at 02:09 PM 0
Share

sometimes the simplicity of even such a small operator let's me stand in awe and marvel over the opportunities. No, seriously, math is fun and a friend of game devs!

avatar image save · Jun 10, 2011 at 02:10 PM 0
Share

Cheers $$anonymous$$ike, +rep for $$anonymous$$ching me something new today. :-)

avatar image DorkNemesis · Jun 10, 2011 at 03:17 PM 0
Share

Thanks a ton, $$anonymous$$ike!

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 do use the % operator? 2 Answers

How to multiply two vector4 3 Answers

Is there a modulus operator in Unity JavaScript? 4 Answers

Need help with Inventory stacker. PLEASE. Almost working! 0 Answers

unity3d simple inventory 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