I want object to break into many pieces once it drops onto the ground.
Yes, the following code worked but instead of instantiating ONE broken model, MULTIPLE models were instantiated.
I wondered what caused the problem. Sometimes it worked, spawning only 1 model, but sometimes 2 or even 3 models are spawned.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectBreak : MonoBehaviour
{
public GameObject destroyedVersion;
public float breakVelocity;
void OnCollisionEnter(Collision colliion)
{
if (colliion.relativeVelocity.magnitude > breakVelocity)
{
Destroy(gameObject);
Instantiate(destroyedVersion, transform.position, transform.rotation);
}
}
}