Rotate 4 prefabs a time, while the clone stays.

OK, what am I really doing.

created an array(game object array). Instantiate them accordingly that it looks like a 4x4 grid. then When the “button1” is pressed then the cubes 1, 2,- 4,5(when counting from bottom left) should rotate on a said axis. But I’m getting a Field ‘UnityEngine.GameObject.isRotating’ not found., error. There are actually four different colored cubes, and currently I’m trying to rotate with one cube. The First code is attached to an empty game object and second code is attached to the cubes (4 cubes have same code attached to them).

First Code:-

var blueSquare:GameObject;
var redSquare:GameObject;
var greenSquare:GameObject;
var yellowSquare:GameObject;

var i:float=0;
var j:float =1;



static var squareLevel1:GameObject[]=new GameObject[15];

function Start () 
{
	
	
	squareLevel1=[blueSquare, redSquare, yellowSquare, greenSquare, redSquare, greenSquare, blueSquare, yellowSquare, blueSquare, redSquare, yellowSquare, greenSquare, redSquare, greenSquare, blueSquare, yellowSquare ];
	
	for(k=0; k<squareLevel1.length;k++)
	{
		i++;
		
				Instantiate(squareLevel1[k], Vector3(i,j,0),Quaternion.identity);		
		

		
		
		if(i==4)
		{
		 	i=0;
		 	j++;
		}
	}
}

function OnGUI()
{
	
	if (GUI.Button(Rect(10,70,50,30),"Click"))
	{	
		squareLevel1[0].isRotating=true;
	}
	
}

here the goes the second code which is attached to the cubes(all 4 have same code attached)

static var isRotating:boolean=false; 
var cubePositon= new Vector3(0,0,0);


public var totalRotation:float=0;

function Update()
 {
	var pointOne=new Vector3(-0.5,-0.5,0);
	var axisPoint=new Vector3(0,0,-1);
	
	var spinAmount:float=25*Time.deltaTime;

	if(isRotating)
	{
	if(totalRotation<90)
	{
		//Debug.Log(gameObject);
		transform.RotateAround (pointOne, axisPoint, spinAmount);
	}
	else if(totalRotation>=90)
	{
		totalRotation=0;
		isRotating=false;
	}

	totalRotation+=spinAmount;
	cubePosition=transform.position;
	Debug.Log("blue : "+isRotating);
}
}

Can anyone please tell me what should be done!!! :frowning:

Two things to fix:

  1. I’m guessing you want each cube to be able to individually rotate, or not (otherwise why write squareLevel1[0].isRotating=true; to set just #0 rotating.) To do that, lose the static:

    static var isRotating:boolean=false; // get rid of the word “static” here

Static is a very special-case thing, it confuses a lot of people, and you never need to use it for anything. In this case, it breaks the isRotating variable.

  1. To look at a script variable, you need one extra step – you have to first go to the script, then the variable. For example, you can’t check thing’s sideways with thing.x – you have to say thing.position.x.

The procedure to look up a script is a little longer, since your script isn’t a built-in part of Unity. Should be:

squareLevel1[0].GetComponent(CubeScript).isRotating
               ^^^^^^^^^^^^^^^^^^^^^^^^^

The reference is at http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

The corrected code goes here:- Things are bit messy I think, will try to clear it up here though!!! :slight_smile:

for(k=0; k<squareLevel1.length;k++)
	{
		i++;

      //squarelevel11 is another gameobject array and it stores the instantiated objects value.

		squareLevel11[k]=Instantiate(squareLevel1[k], Vector3(i,j,0),Quaternion.identity);		
		
//		Debug.Log(squareLevel1[1]);
		
		
		if(i==4)
		{
		 	i=0;
		 	j++;
		}
	}
}

function OnGUI()
{
	
	if (GUI.Button(Rect(10,70,50,30),"Click"))
	{	
//		Debug.Log(squareLevel1[0].GetComponent(BlueCube).isRotating);
		squareLevel11[0].GetComponent(BlueCube).isRotating=true;
		squareLevel11[1].GetComponent(BlueCube).isRotating=true;
		squareLevel11[4].GetComponent(BlueCube).isRotating=true;
		squareLevel11[5].GetComponent(BlueCube).isRotating=true;
		
	}
	
}