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!!! ![]()
will try with this and roll back to you. ty
– ArunChnadrantried that too. now its not giving any errors, but its not rotating!! :-(
– ArunChnadranYou have a Debug line. Does it ever print "blue:"? Try printing totalRotation in that same debug. Add a debug line "clicked" in OnGUI for the 1st script -- maybe you have the wrong area for the button. As you run select a few things and check the Inspector. Maybe somehow totalRotation is always 9999.
– Owen-Reynoldsthanks owen for ur help! the tips worked out and there is some other thing I did that at the time of "Instantiate"ion.
– ArunChnadran