36 lines
936 B
C#
36 lines
936 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ShardsDestroyer : MonoBehaviour {
|
|
|
|
public float lifeTime = 5.0f;
|
|
public float explosionAmount = 1f;
|
|
|
|
private IEnumerator Start()
|
|
{
|
|
if (explosionAmount > 0f)
|
|
{
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
{
|
|
Rigidbody child = transform.GetChild(i).GetComponent<Rigidbody>();
|
|
if (child != null)
|
|
{
|
|
child.AddExplosionForce(explosionAmount, transform.position, 3f);
|
|
}
|
|
}
|
|
}
|
|
yield return new WaitForSeconds(lifeTime);
|
|
AudioSource audio = GetComponent<AudioSource>();
|
|
if (audio != null)
|
|
{
|
|
while (audio.isPlaying)
|
|
{
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
}
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
}
|