using System.Collections.Generic; using UnityEngine; namespace KD.Destro2D{ public class DoBasicDestruction : MonoBehaviour { [SerializeReference] public List destructions = new(); [Header("Burn colors correspond to destructions in order, make sure to have SAME COUNT")] public List burncolors = new(); public float radius = 1f; public bool doMainDestruction = false; void OnEnable() { Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radius); foreach(Collider2D c in col) { if(c.TryGetComponent(out var d)){ //important to setup when dealing with other object for(int i = 0; i < destructions.Count; i++) { var dest = destructions[i]; var color = burncolors[i]; dest.SetupWithColor(c.gameObject,color); } d.DynamicDestroyWorld(transform.position,destructions); if(doMainDestruction) d.DynamicDestroyWorld(transform.position); } } Destroy(this.gameObject); } } }