- Home /
Question by
fleischverpackung · Apr 07, 2016 at 12:44 AM ·
c#arrayobjectsgeneratedynamically
create objects by script and fill them into array
hi all,
quite new to c# and struggling to create an array objects, I can use later on in my code. right now I'm doing this:
public Light light0;
public Light light1;
void Start()
{ lightArr = new Light[]
{
light0,
light1,
};
}
void Update()
{for (int i = 0; i < lightArr.Length; i++)
{
lightArr[i].transform.position = (new Vector3(UDPClient.lights[i * 3], UDPClient.lights[i * 3 + 1], UDPClient.lights[i * 3 + 2]));
}
}
I can generate those lightobjects by code, but I don't know how to fill them into an array like my old one. I want to update thier positions via UDP.
for (int i = 0; i < 2; i++)
{
GameObject gObjekt = new GameObject("generatedLight" + i.ToString());
Light gLight = gObjekt.AddComponent<Light>();
gLight.color = Color.blue;
gLight.transform.position = new Vector3(0, 0, 0);
}
would appreciate some help on this :) and btw do you guys instantiate or generate? is it more practable to have this prototype you can modify or whats the reason?
thanks!
Comment
Your answer
Follow this Question
Related Questions
List out all Array Values. 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Assign a String to Each int 1 Answer
How to check the state of booleans in an bool array, reading from index "a" to "b"? 3 Answers