UI update 02
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
namespace KD.Destro2D{
|
||||
public class DoExplosion : MonoBehaviour
|
||||
{
|
||||
public float radiusCore = 0f;
|
||||
public float radiusOuter = 1f;
|
||||
public float noiseScale = 20f;
|
||||
public float thickness = 0.12f;
|
||||
public float force = 100f;
|
||||
void OnEnable()
|
||||
{
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radiusOuter);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<Destro2DMain>(out var d)){
|
||||
d.DynamicFracture(transform.position,radiusCore,radiusOuter,noiseScale,thickness,5);
|
||||
}
|
||||
|
||||
}
|
||||
StartCoroutine(AddForce());
|
||||
}
|
||||
IEnumerator AddForce()
|
||||
{
|
||||
//delay for the chunks to actually split
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
//detect again, then add force
|
||||
Collider2D[] col = Physics2D.OverlapCircleAll(transform.position,radiusOuter);
|
||||
foreach(Collider2D c in col)
|
||||
{
|
||||
if(c.TryGetComponent<SplitHandler>(out var s) && c.TryGetComponent<Rigidbody2D>(out var rb))
|
||||
{
|
||||
Vector2 worldChunkCentre = c.transform.TransformPoint(s.chunkCentre);
|
||||
Vector2 dir = worldChunkCentre - (Vector2)transform.position;
|
||||
rb.AddForce(dir.normalized * force);
|
||||
}
|
||||
}
|
||||
Destroy(this.gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user