- Home /
Add existing variables to an array?
I have a few float variables and an array
public float zero = 10.5;
public float one = 25;
public float two = 50;
public float three = 75;
public float four = 12.5;
public float five = -65;
float[] numbers;
can I make these variables go into the (or an) array so that they are indexed and I can use them from other scripts by writing something like:
float otherZero;
otherZero = FirstScript.numbers[0] //meaning it's value will be 10.5
i'm am not sure if this is possible or how to do it. i've been watching a lot of tutorials on loops/lists/arrays and classes but it's just not coming to me
Answer by Dragate · Nov 14, 2017 at 07:08 AM
This is how I define an array with initial values:
public float[] numbers = {10.5f, 25, 50, 75, 12.5f, -65};
well that's actually what I have after seeing it in the tutorial series but I wanted to make it better which would be having the names "zero - length" in inspector so I don't have to remember what number 12 did exactly when assigning the value to a new object when I put the script on if in the inspector it said ''number of triangles" ins$$anonymous$$d of ''element 12". I also looked up changing the ''element #" but it looked complicated so I was just wondering if there was a way to feed an array variables even though I thought there wouldn't be (i'm new). never hurt to ask! thanks though ;) if I really want it i'll look more into the other way
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Problem with List 0 Answers
Searching a List of GameObjects by name 2 Answers
loop with array system 0 Answers