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();
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!
↧