Hi community I am in need of a little assistance. I'm relatively new to JS (or any other language for that matter and have hit a snag. I have managed to cobble together a script for objects in my game that dictates what happens when they fall through the world or out of bounds or fall asleep. The problem I'm having is what I want is for the balls to spawn at 2 (or three or four depending on var) points in the level, but only 1 then the next and so forth. It's to evenly distribute balls amongst the players. Seeing as I am not a scripting genius I can't seem to figure it out without your help.
EXAMPLE IMAGE
![alt text][1]
[1]: /storage/temp/12093-example.png
MY CODE:
#pragma strict
var floorHeight = 0;
var spawnHeight = .03;
function Update ()
{
if(transform.position.y < floorHeight) //if falls through floor transform to int up
{
transform.position.y = spawnHeight;
}
if(transform.position.y > .5) //above floor .5
{
rigidbody.AddForce (0, -30, 0); // accelerate its speed down
}
if(rigidbody.IsSleeping()) //if at rest transform location to position
{
transform.position = Vector3(Random.Range(4, 7), 1.6, 6.7);
}
//This line of code is to add random movement to ball if sleeping
// if(rigidbody.IsSleeping())
// {
// rigidbody.velocity = Vector3(Random.Range(-5.0, 5.0), 0.01, Random.Range(-5.0, 5.0));
// }
}
↧