Files
2026-06-30 21:21:30 +08:00

37 lines
1.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
namespace KD.Destro2D{
public class DoBasicDestruction : MonoBehaviour
{
[SerializeReference]
public List<Destruction> destructions = new();
[Header("Burn colors correspond to destructions in order, make sure to have SAME COUNT")]
public List<Color> 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<Destro2DMain>(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);
}
}
}