I have a simple script, that places copies of a prefab object on the scene at a certain order.
To the prefab is attached the following script:
var x:float = 0.0;
var y:float = 90.0;
function Start ()
{
var z:int;
z=Random.Range(1.0, 4.0);
x=(y*z);
transform.Rotate(0.0, x, 0.0);
print(x);
}
function Update ()
{
}
This script is supposed to turn the object by 90 degrees on y axis up to four times on start, in order to randomize the placement, but keeping the structure.
Problem is, when I launch the placement script, those prefabs that are turned are placed out of their place in structure.
Prefab consists of a three cubes, that are combined in an empty object.
Here is a placement script, just in case. It works fine by itself. It creates a grid of prefabs, placed in a square with a changeable distance between them and the size of a square itself.
var Xvalue:float = 0.0;
var Zvalue:float = 0.0;
var ChangeCounter:int = 1.0;
var ChangeAmount:float = 20.0;
var Technical_Couter:int = 1.0;
var PlayFieldSize:float = 0.0;
var prefab1:Transform;
var a:float=1.0;
var b:float=1.0;
function Update ()
{
if(ChangeCounter<PlayFieldSize)
{
Xvalue=(ChangeAmount*ChangeCounter);
Instantiate (prefab1, Vector3(Xvalue, 0.0, 0.0), Quaternion.identity);
print("Starting a new circle, placing first platform");
//On the first circle x=0
if(ChangeCounter>0)
{
while(Technical_Couter<(ChangeCounter+1))
{
Zvalue=(ChangeAmount*Technical_Couter);
Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
print("vertical row");
print(a);
a++;
Technical_Couter++;
}
while(Xvalue>0)
{
Xvalue=(Xvalue-ChangeAmount);
Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
print("horizontal row");
print(b);
b++;
}
}
a=1.0;
b=1.0;
ChangeCounter++;
Technical_Couter=1.0;
}
}