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 d112570 · Aug 23, 2013 at 06:20 PM · inspectorserializableelement

How do you Get Variables with 2 or more Elements?

How do I get the Variables I edited in the Inspector using serialized Properties?

How would I get X of Element 1 and X of Element 2? How would I get the name of Element 1 and 2 etc?

In c# please and you may use Print for an example, like Print("Name: " + name + " Element: " + ID); etc. The ID I like to use is the element number, how would you go about doing that. In inspector it would says Element 0, then Element 1

Been searching for 3 days, looking at tutorials and such with no prevail.

This is my script (I made it smaller to not confuse anyone, my original one has like 22 blanks to fill in.)

I would love to hear your ideas, thanks in advanced. :-)

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
     
     
     //The Properties
     [System.Serializable]
     public class objectSize {
         public float X;
         public float Y;
         public float Z;
         }
     
     [System.Serializable]
     public class StarSystem
     
     {
         public string name;
         public GameObject gameObject;
         public objectSize objectSize2;
     }
     
     public StarSystem[] StarSystemSizeSetup;
     
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }

//The Inspector looks like this.

alt text

1.png (18.9 kB)
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
2
Best Answer

Answer by Owen-Reynolds · Aug 23, 2013 at 11:30 PM

There's nothing special about using an "Inspector variable." Read/Write it the same way as always. For example, the bottom Z value is StarSystemSizeSetup[1].objectSize2.Z; and the name is SSSSetup[1].name;

To break it down, SSSS is an array, so needs [0], [1] .. after it. The Inspector even uses the correct C# numbering, stating at 0. The items in the array are StarSystem variables, so need to have dot-name, dot-gameObject or dot-ObjSz2.

If you get confused about using other combinations of classes and arrays, just look at any (non-Unity) C# examples.

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
avatar image
0

Answer by d112570 · Aug 24, 2013 at 08:54 AM

Thankyou so much, easier then I thought.

Here is my print example for others with the same question.

print("Planet Name: " + StarSystemSizeSetup[1].name + " - Diameter: " + StarSystemSizeSetup[1].objectSize.Z);

0 is used Element 0 1 is used Element 1 etc

But once you type in the name using "public string name;" for each Element - the name "Element" will use the new name "Mercury" for example.

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

16 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

Related Questions

Custom Display for system.object Editor 1 Answer

Logic Problems using for loops 0 Answers

Custom abstract class (and inheritance) not allowing public array despite having System.Serializable? 1 Answer

Why aren't my editor values saving when I press play? 3 Answers

Displaying objects in lists of lists. 2 Answers


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