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.

52 lines
956 B

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