You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
860 B

  1. using UnityEngine;
  2. using System.Collections;
  3. public class PlayerExplosion : MonoBehaviour {
  4. public float explosionDistance;
  5. public float explosionTime;
  6. public int fraqAmount = 0;
  7. // Use this for initialization
  8. void Start () {
  9. foreach (Transform child in transform)
  10. {
  11. fraqAmount++;
  12. StartCoroutine (explosion (child));
  13. }
  14. }
  15. // Update is called once per frame
  16. void Update () {
  17. }
  18. IEnumerator explosion(Transform debris){
  19. Vector3 centre = transform.position;
  20. Vector3 scaleDirection = debris.position - centre;
  21. Debug.Log ("Scale Direction" + scaleDirection);
  22. for (float i = 0; i < 1; i += Time.deltaTime/explosionTime) {
  23. debris.position =centre +( scaleDirection * Mathf.Lerp (1, explosionDistance, i));
  24. yield return null;
  25. }
  26. fraqAmount--;
  27. if (fraqAmount == 0) {
  28. Destroy(gameObject,0.0f);
  29. }
  30. }
  31. }