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

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);
}
}