using System.Collections; using System.Collections.Generic; using UnityEngine; public class DebrisPiece : MonoBehaviour { private Rigidbody _rb; private void Awake() { _rb = GetComponent(); if (_rb == null) _rb = gameObject.AddComponent(); } public void Launch(Vector3 explosionPos, float force, Material material) { if (material != null) { MeshRenderer mr = GetComponent(); if (mr != null) mr.sharedMaterial = material; } _rb.AddExplosionForce(force, explosionPos, 20f, 3f, ForceMode.Impulse); _rb.AddTorque(Random.insideUnitSphere * force * 0.8f, ForceMode.Impulse); Destroy(gameObject, Random.Range(3f, 7f)); } }