- Home /
Question by
ina · Feb 18, 2012 at 10:31 PM ·
instantiatelistarrayspropertiescollections
Instantiate to temp var or directly adding to list?
When instantiating an object with properties other than the original prefab, is it better to do this:
Declare a temp var and change its properties, then add to list
var o:GameObject = Instantiate(fred,Vector3.zero,Quaternion.identity); o.renderer.material.color = RandColor(); list.Add(o);
or this:
Add to list directly, then reference last added list element to change its properties.
list.Add(Instantiate(fred,Vector3.zero,Quaternion.identity)); list[listCount].renderer.material.color = RandColor();
Comment
Answer by Berenger · Feb 19, 2012 at 12:19 AM
I'll go for the first one, as you spare yourself a list access. Not much of a difference though.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to get a List of all Variables in a Class 1 Answer
Prefabs instantiated from an array are keeping their public int value 1 Answer
How Do I Add An Instantiated Object To An Array? 3 Answers
Javascript containing List<> - can not make them work in WebPlayer 1 Answer