|
|
- using UnityEngine;
- using System.Collections;
-
- public class SpawnController : MonoBehaviour {
-
- private EnemyController controller;
- private CircleCollider2D boxCollider;
- public Material mat;
- public float animationTime = 5f;
- public Color startColor;
- public Color endColor;
-
-
- // Use this for initialization
- void Start () {
- controller = GetComponentInParent<EnemyController>();
- boxCollider = GetComponentInParent<CircleCollider2D>();
-
- mat = new Material(GetComponentInChildren<Renderer>().material);
- transform.Find("SpawnCube").GetComponentInChildren<Renderer>().material = mat;
-
-
- StartCoroutine(spawn(animationTime));
- }
-
- private IEnumerator spawn(float time) {
- float elapsedTime = 0;
- Color transitionColor = startColor;
-
- while ((elapsedTime / time) <= 1) {
- transitionColor = Color.Lerp(startColor, endColor, (elapsedTime / time));
- mat.color = transitionColor;
-
- elapsedTime += Time.deltaTime;
- yield return new WaitForEndOfFrame();
- }
-
-
-
- controller.enabled = true;
- boxCollider.enabled = true;
- Destroy(gameObject);
- }
- }
|