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
0
Question by ChrisWarner103 · Mar 10, 2018 at 09:38 PM · multipleintegerstoring

Storing multiple integers into one

Hello, this question is very stupid. But I am making a padlock script that is unlocked with 4 different integers and I was wondering if there is any way of making it so that for example. If you have a main int called currentCode. What I want to do is set all of the 4 integers into 1. So it would be like option1, option2, option3 and option4 would be for example (6 4 7 8) as the separate integers. Then I want the currentCode to display the 4 options (6478).

If there isn't any way of doing this that's fine as long as someone can guide me in the direction I need to go towards.

Like if I could do something like currentCode = option1, option2, option3, option4; That would be great but that doesnt seem to be the case

Comment
Add comment · Show 4
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 meat5000 ♦ · Mar 10, 2018 at 09:42 PM 0
Share

There is no need to consider this as far as the specifics of the coding go. Only for display purposes. You can do something like this, however, using an Array

avatar image ChrisWarner103 meat5000 ♦ · Mar 10, 2018 at 09:45 PM 0
Share

Thank you for the quick reply

Okay, so is there any way of doing this with arrays then. So like being able to set 4 options of the array to the 4 integers?

avatar image ChrisWarner103 meat5000 ♦ · Mar 10, 2018 at 09:54 PM 0
Share

Also, was just thinking. Would I be able to do this with strings ins$$anonymous$$d?

avatar image meat5000 ♦ ChrisWarner103 · Mar 11, 2018 at 09:08 AM 0
Share

You can make an array of anything, more or less. string[] 1d string array string[][] 2d string array.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Mar 11, 2018 at 11:02 AM

The solution to your problem is enum with Flag attribute.

 [System.Flags]
 public enum Option
 {
     First = 0,
     Second = 1,
     Third = 2,
     Fourth = 4,
     Fifth = 8
 }

Notice the give value are power of two.

You can then declare an enum reference and add values to it.

 Option options = Option.First;
 options |= Option.Third;
 options | = Option.Fifth;

this contains First, Third and Fifth.

You can figure out if it contains a specific value:

 private bool ContainsValue(Option value)
 {
      return ((options & value) == value);
 }

And you can remove a flag with:

 options &= ~Option.Third;

Plenty of it over the internet.

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

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

74 People are following this question.

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

Related Questions

Detecting multiples of 2 3 Answers

laser is not working 0 Answers

Animating 2D Character made up of 2 or more swapable sprites 1 Answer

Best way to create multiple characters with the same stats 1 Answer

Shader - Using Multiple Pass for different shader target 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