- Home /
script syntax
Hey guys,
I'm trying to get the code below to work, but having little success. What can I do to get this to work? The part that is not working is once 4 cubes are destroyed gravity should turn on for the remaining cubes so they fall:
var smokePrefab: Transform;
var int objectDestroyed = 0;
//Invoke("OnCollisionEnter", 2);
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == "missile_1")
{
Destroy (gameObject);
Instantiate (smokePrefab, transform.position, transform.rotation);
++objectDestroyed;
}
{
if objectDestroyed == 4;
{
gameObject.rigidbody.useGravity = true;
}
}
Sorry for the ugly code, I'm new to scripting.
Thanks,
Stef
Answer by Berenger · Mar 09, 2012 at 11:16 PM
You are enabling gravity for the gameObject you destroy, that won't do much. You probably need to get an array of the remaining cubes, preferably with a tag and a Find function, then set rigidbody.useGravity = true; on those guys.
Your answer
Follow this Question
Related Questions
TURN GRAVITY ON! 1 Answer
4 blocks destroyed - gravity true 2 Answers
how can i get weight that the rigidbody's gravity is aplying to an object 2 Answers
How to edit scene gravity? 0 Answers
A Rigidbody moving in a moving Rigidbody 0 Answers