I’m still trying to figure this scripting thing out and I’m not sure what I’m doing wrong here so any help would be greatly appreciated. So, I’m basically trying to spawn a random object from 4 pre-defined objects then figure out when that object is done falling to the ground and spawn another random object when it stops moving. I’m not sure what’s wrong since I had gotten it to work a couple times (work as in run, not as in function the way I’m trying to make it function), but when I changed it a little to try to make it run better, it started giving me the Mac rainbow pinwheel thing again so I took it out and now it’s still doing it after restarting, etc. Here’s what I have so far.
var randomShape : int;
var shapeOne : GameObject;
var shapeTwo : GameObject;
var shapeThree : GameObject;
var shapeFour : GameObject;
var cutoffVelocity : float = 0.01;
var stopped : boolean = true;
function Start()
{
randomShape = Random.Range(1,4);
if(randomShape == 1)
{
Instantiate(shapeOne, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 2)
{
Instantiate(shapeTwo, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 3)
{
Instantiate(shapeThree, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 4)
{
Instantiate(shapeFour, transform.localPosition, Quaternion.identity);
}
GenerateNumber();
}
function GenerateNumber()
{
randomShape = Random.Range(1,4);
SpawnShape();
}
function SpawnShape()
{
Check();
if (stopped)
{
if(randomShape == 1)
{
Instantiate(shapeOne, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 2)
{
Instantiate(shapeTwo, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 3)
{
Instantiate(shapeThree, transform.localPosition, Quaternion.identity);
shapeTouched = false;
}
else if(randomShape == 4)
{
Instantiate(shapeFour, transform.localPosition, Quaternion.identity);
}
GenerateNumber();
}
}
function Check()
{
stopped = true;
var shapes = new Array (GameObject.FindGameObjectsWithTag("Shape"));
for ( var shape in shapes )
{
if(shape.rigidbody.velocity.magnitude > cutoffVelocity || shape.rigidbody.angularVelocity.magnitude > cutoffVelocity)
{
stopped = false;
break;
}
}
}