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.

44 lines
1.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class SpawnController : MonoBehaviour {
  4. private EnemyController controller;
  5. private CircleCollider2D boxCollider;
  6. public Material mat;
  7. public float animationTime = 5f;
  8. public Color startColor;
  9. public Color endColor;
  10. // Use this for initialization
  11. void Start () {
  12. controller = GetComponentInParent<EnemyController>();
  13. boxCollider = GetComponentInParent<CircleCollider2D>();
  14. mat = new Material(GetComponentInChildren<Renderer>().material);
  15. transform.Find("SpawnCube").GetComponentInChildren<Renderer>().material = mat;
  16. StartCoroutine(spawn(animationTime));
  17. }
  18. private IEnumerator spawn(float time) {
  19. float elapsedTime = 0;
  20. Color transitionColor = startColor;
  21. while ((elapsedTime / time) <= 1) {
  22. transitionColor = Color.Lerp(startColor, endColor, (elapsedTime / time));
  23. mat.color = transitionColor;
  24. elapsedTime += Time.deltaTime;
  25. yield return new WaitForEndOfFrame();
  26. }
  27. controller.enabled = true;
  28. boxCollider.enabled = true;
  29. Destroy(gameObject);
  30. }
  31. }