Quantcast
Channel: Questions in topic: "dynamically"
Viewing all articles
Browse latest Browse all 152

create objects by script and fill them into array

$
0
0
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!

Viewing all articles
Browse latest Browse all 152

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>