Esempio n. 1
0
    IEnumerator SpawnHostile()
    {
        if (currentHostiles < maxHostiles)
        {
            spawning = true;
            yield return(new WaitForSeconds(Random.Range(1, 4)));

            Vector3    spawnPosition = new Vector3(15, Random.Range(-4.5f, 4.5f), 0);
            GameObject newHostile    = Instantiate(hostile, spawnPosition, Quaternion.identity);
            Hostile    hostileScript = newHostile.GetComponent <Hostile>();
            hostileScript.OnHostileDeath += HostileDeath;
            hostileScript.OnHostileDeath += player.OnHostileDeath;
            hostileScript.AssignRelativeMotion(relativeMotion);
            currentHostiles++;
            StartCoroutine(SpawnHostile());
        }
        else
        {
            spawning = false;
        }
        yield return(null);
    }