- Home /
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.
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.
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.
Your answer

Follow this Question
Related Questions
Custom Display for system.object Editor 1 Answer
Logic Problems using for loops 0 Answers
Why aren't my editor values saving when I press play? 3 Answers
Displaying objects in lists of lists. 2 Answers