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 /
  • Help Room /
avatar image
0
Question by Rick74 · Jan 16, 2016 at 09:10 PM · c#arraysclassesdatatype

Arrays with multiple data types C#

So I've heard this trick is pretty great at just handling data storage. And I wanna learn how to use it, but a few things I'm fuzzy on.

I've read this answer, http://answers.unity3d.com/questions/698312/store-multiple-types-of-data-in-an-array.html but unfortunately I'm still learning C# and there are some things I'm fuzzy on. If I create a class;

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ButtonData : MonoBehaviour
 {
     public GameObject    buttonGameObject;
     public Image          buttonImage;
     public Button         button;
     public float         coolDown;
     public int            value;
 }
 

And then I call that class to create an array within another class;

     public ButtonData[]            allButtonData;    

How come if I remove : MonoBehavior from the ButtonData class, the array of buttonData [] disappears in the inspector?

And where do I fill in the values of each entry? It can't be done within the inspector as that only seems to be looking for objects containing that class?

I guess I was sort of expecting a means to house data and then enter that data in the inspector like you can with any other single data type array.

So if anyone knows of a great tutorial page or documentation as to how and coders use this method, I'd love to read it.

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

Answer by instruct9r · Jan 16, 2016 at 09:32 PM

You have to serialize the Class.

So above the class declaration type:

 [System.Serializable]

And you can remove the MonoBehaviour inheritance. You can just leave it as class, that doesn't inherit from anything.

Now you can declare an instance of that class in a MonoBehaviour script...

If i understand correctly your question..

Comment
Add comment · Show 1 · 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 Rick74 · Jan 17, 2016 at 04:47 PM 0
Share

Thanks instructor, that worked!

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

55 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

Related Questions

Managing In-Game Variables of Different Data Types 1 Answer

Null reference exception in an if statement that checks for it. 1 Answer

I have an array from which spawns a random image. Instantiate spawning full pool on start 1 Answer

Using a class to control two "player" objects 1 Answer

Game Manager can't decide what the instance of the object is despite just making an instance of it 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