C# script to make object shatter into smaller objects.
Fristly add Cube and attach Rigidbody and below script to it. After that create empty GameObject, reset it’s position and add cubes with Rigidbodies to match the cube that was added previously. Next, save that GameObject as a prefab and add it to the script of the main cube. After that simply call the DestroyObject function from the script.
using System.Collections; using System.Collections.Generic; using UnityEngine; // ? 2017 TheFlyingKeyboard and released under MIT License // theflyingkeyboard.net public class DestroyableObject : MonoBehaviour { public GameObject fragments; private void OnMouseDown() { Instantiate(fragments, transform.position, transform.rotation); gameObject.SetActive(false); } }