Exemple #1
0
    IEnumerator SpawnEnemy()
    {
        float spawnDelay = 1;
        float flashSpeed = 4;

        Transform randTile = map.GetRandomOpenTile();

        Material getMaterial  = randTile.GetComponent <Renderer>().material;
        Color    initialColor = getMaterial.color;
        Color    flashColor   = Color.red;

        float spawnTimer = 0;

        while (spawnTimer < spawnDelay)
        {
            getMaterial.color = Color.Lerp(initialColor, flashColor, Mathf.PingPong(spawnTimer * flashSpeed, 1));
            spawnTimer       += Time.deltaTime;
            yield return(null);
        }

        AI spawnedEnemy = Instantiate(enemyAI, randTile.position + Vector3.up, Quaternion.identity) as AI;

        spawnedEnemy.OnDeath += OnEnemyDeath;
    }