How to make a dice fall when space bar is pressed.

I am making a simple craps game for my brother and i need to find out how to roll the die when the space bar pressed. Until, the space bar is pressed the die will just be in midair until you press space. So i need some script that will turn the die into a rigid body component when the space bar is pressed and when not pressed just sit there. Please help.

One way is to use the isKinematic flag of the Rigidbody. Set it to true in the Rigidbody component in the inspector. To roll the dice put this script on each die:

function Update() {
    if (Input.GetKeyDown(KeyCode.Space)) {
        rigidbody.isKinematic = false;

You may also want to add just a bit of torque to each die in the same ‘if’ statment:

rigidbody.AddRelativeTorque(3 * Random.value, 3 * Random.value, 3 * Random.value);

The ‘3’ is just a guess.

You can have the rigid body’s already attached to the die. Just make sure that you have the “Use Gravity” checkbox unchecked. When you press space, enable the gravity. Simple as that.

Should look something like this:

function Update () 
	if (Input.GetKeyDown ("space"))
        gameObject.rigidbody.useGravity = true;

And this script would have to be attached to the die game objects of course.

Wow, thanks so much guys. I put the code in the box and it worked perfectly! Thanks so much again!