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
0
Question by aosome23 · Jul 03, 2014 at 03:52 AM · variablebooleanmultipleintnew

Store Multiple values in one variable

Is there a way to store multiple values in one variable? For example, there is a variable named sample. And var sample equals to an int of 5 and also an Boolean of true.

i.e. var sample = new (int 5, bool true); or something like this...

I feel like there is some sort of way of doing this since vector 3 can hold multiple values(x y and z).

I thought that an array might work but this variable has to go into an array. What I mean by this is: anArray.add(sample);

So is there anyway of doing this? thanks!

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

2 Replies

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

Answer by Kiwasi · Jul 03, 2014 at 04:00 AM

Two ways to do this, struct or a class. The key difference is that struct is passed by value and class is passed by reference.

Comment
Add comment · Show 3 · 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 aosome23 · Jul 03, 2014 at 04:35 AM 0
Share

Thank you for a quick reply!!

However, I am quite inexperienced in coding and also a newbie at C#. Would you be able to write a short example code declaring the struct or classes?

Although I spent a while reading the documentation you have shown me, I still quite don't understand how both of them work. (Especially classes)

Thank you again!

[EDIT] Also, would I be able to push this into an Array or a List?

avatar image aosome23 · Jul 03, 2014 at 07:56 AM 0
Share

Never$$anonymous$$d, I figured it out!!! I feel so smart haha :p Anyways thanks for your help!! Structs and classes are very useful. I believe that there is none of these in javascript is there?

avatar image Kiwasi · Jul 03, 2014 at 09:49 PM 0
Share

JavaScript can do most things that C# can do. Classes and structs are kind of fundamental to OOP, so it should be able to do it.

However as a free piece of advice I would say learn C# ins$$anonymous$$d of JavaScript. There are a bunch of different reasons. Ultimately C# is more powerful, less error prone and exists outside of Unity.

avatar image
0

Answer by bhartu · Jul 03, 2014 at 06:14 AM

you can use Dictionary to store two values.

like,

 private Dictionary<int, bool> myDisctionary = new Dictionary<int, bool>;
 
 myDisctionary.Add(12, false);
 
 Debug.log(myDisctionary[12]); // will print false


   



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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Static Variable Problem 1 Answer

Sharing booleans between 2 scripts 1 Answer

Pass a function(float) as variable 2 Answers

Displaying variable on UI text every frame (JS) 1 Answer

How to write "if (var int = var int 2)" ? 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