- Home /
Objects falling from the specific height randomly.
Supposed i have a two ball on same position and falling from sky. when i play the game the object falling from sky for this i know we can use. "rigidbody.AddForce(Physics.gravity);" but i want that object fall randomly means no one understand which ball fall first.I am using counter but its not work randomly.
var counter:int=0;
function Update () { counter+=1; }
function FixedUpdate(){ if(counter>200) { rigidbody.AddForce(Physics.gravity); }
}
Answer by Nick4 · Jan 15, 2014 at 11:06 AM
var counter:int=0;
function Update () {
counter+=1;
}
function FixedUpdate(){
if(counter>(Random.Range(190,210)){
rigidbody.AddForce(Physics.gravity);
}
}
Something like this, perhaps?
thanks for help but my problem is i have 4 object on sky and falling one by one but it should be random chooser and more important thing when one object hit the ground then other object start falling.this is possible.
Answer by Sundar · Jan 14, 2014 at 12:45 PM
Use Random.Range http://docs.unity3d.com/Documentation/ScriptReference/Random.Range.html
Int aRandom = Random.Range( 0, 2);
thanks for your idea but its not working. i have two different object in a scene and both the object falling from sky by using gravity.I want first object fall then second but not constant means randomly use the object which one fall first.