- Home /
Question by
Patyrn · Mar 15, 2011 at 12:56 AM ·
gameobjectrigidbodydestroyondestroy
"Some objects were not cleaned up when closing the scene"
I have a "Giblets" script which OnDestroy clones parts of the gameObject I'm destroying, gives them a rigidbody, and then throws them into the air.
There are two problems with this. First one is when I stop the scene I get the above error message, and they are still in my Hierarchy. Second problem is that even with the rigidbody they fall right through the floor. Any ideas?
Here's the code:
public class Giblits : MonoBehaviour { public GameObject[] giblets;
void OnDestroy() {
GameObject instaGib;
foreach (GameObject gib in giblets) {
instaGib = (GameObject) Instantiate(gib, gib.transform.position, gib.transform.rotation);
instaGib.AddComponent("Rigidbody");
Vector3 force = new Vector3(Random.Range(-5,5), Random.Range(15,25), Random.Range(-5,5));
Vector3 torque = new Vector3(Random.Range(-5,5), Random.Range(-5,5), Random.Range(-5,5));
instaGib.rigidbody.AddForce(force, ForceMode.Impulse);
instaGib.rigidbody.AddTorque(torque, ForceMode.Impulse);
Destroy(instaGib, 3);
}
}
}
Comment
Best Answer
Answer by Antony-Blackett · May 25, 2011 at 10:58 PM
I was having the same trouble. This answer to another question should solve your issue. http://answers.unity3d.com/questions/54674/is-there-a-way-to-know-when-the-application-is-in.html