var prefab : GameObject;
var numberOfObjects = 10;
var radius = 5;
function Start () {
for (var i = 0; i < numberOfObjects; i++) {
var angle = i * Mathf.PI * 2 / numberOfObjects;
var pos = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
Instantiate(prefab, pos, Quaternion.identity);
}
}
renderer.material.color = yourColor
Assuming you already know all of the colors you need, I would just make an array of Color
objects (Color[]
) that is equal in length to the number of objects you need.
Set all of these colors (either with an initializer list, a loop, or manually). Then, inside of your loop in Start
, you need to change a few things. First off, save the result of Instantiate
to a GameObject
. To do this, change your line to save it to a GameObject
variable.
var myObject : GameObject = Instantiate(prefab, pos, Quaternion.identity);
Essentially, this tells myObject
that it is a GameObject
, and then sets it to be whatever you just created. After this, simply call
myObject.renderer.material.color = myColorArray*; //myColorArray is the previously mentioned color array*
and you should be all set.