Hi everybody,
I’m trying to switch from a grid to a circle representation of a GameObject (prefab), but I cannot get the transition correctly,
here is the code:
it should instantiates a prefab in a grid
var prefab : GameObject;
var gridX = 5;
var gridY = 4;
var spacing = 2.0;
var numberOfObjects : int = 20;
var radius = 2;
var IsGrid : boolean = true;
function Start ()
{
if(Input.GetButtonDown("Fire1"))
IsGrid = !IsGrid;
if(IsGrid == false)
{
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);
}
}
else
{
for (var y = 0; y < gridY; y++) {
for (var x = 0; x < gridX; x++) {
var pos2 = Vector3 (x, 0, y) * spacing;
Instantiate(prefab, pos, Quaternion.identity);
}
}
}
}
and pressing “Fire1” key, should change to the circle, does it make sense? how can i do it?
thanks in advance for anyhelp…