private void Spawn() { int enemies = Random.Range(minEnemies, maxEnemies); bool[] available = new bool[transform.childCount]; Vector2 playerPos = GameManager.instance.GetPlayer().transform.position; int maxSpawns = 0; for (int j = 0; j < available.Length; j++) { Vector2 pos = transform.GetChild(j).transform.position; if (Vector2.Distance(playerPos, pos) > distance) { available[j] = true; maxSpawns++; } else { available[j] = false; } } int i = 0; while (i < enemies && i < maxSpawns && remaining > 0) { int index; do { index = Random.Range(0, transform.childCount); } while (!available[index]); Vector2 pos = transform.GetChild(index).transform.position; GameObject enemy = Instantiate <GameObject>(enemyPrefab, pos, Quaternion.identity, enemyPool); if (enemyPrefab.GetComponent <Portal>()) { PointAtPortal arrow = Instantiate(this.GetComponent <PortalArrow>().portal, GameManager.instance.GetPlayer().transform); arrow.SetTarget(enemy.transform); } remaining--; if (portal) { GameManager.instance.XtraEnemies(1); //Debug.Log("Generado " + enemyPrefab.name + " a " + Vector2.Distance(pos, GameManager.instance.GetPlayer().transform.position)); } i++; } //vuelve a comprobar si ha acabado Invoke("GeneraEnemigos", delay); }
private void OnDestroy() { PointAtPortal[] arrows = new PointAtPortal[GameManager.instance.GetPlayer().GetComponentsInChildren <PointAtPortal>().Length]; arrows = GameManager.instance.GetPlayer().GetComponentsInChildren <PointAtPortal>(); int i = 0; while (i < arrows.Length - 1 && arrows[i] != null && arrows[i].Target != this) { i++; } Destroy(arrows[i].gameObject); GameManager.instance.enemyCount--; GameManager.instance.ChangeHealth(healthRecover, GameManager.instance.GetPlayer()); }
public void SaltaOleada() { Transform enemyPool = GameObject.FindGameObjectWithTag("EnemyPool").transform; foreach (Transform enemy in enemyPool) { Destroy(enemy.gameObject); } generadorOleadas.AcabaOleada(); //int actOl = oleadaActual; enemyCount = 0; if (!GameObject.FindGameObjectWithTag("Ciencia")) { if ((oleadaActual - cientifico.primeraAparicion) % cientifico.cadaX == 0) { //aquí van las visitas del CIENTEFRICO cientifico.Visita(); } else { GeneraOleada(); } } flechas = false; PointAtEnemy[] arrows = new PointAtEnemy[player.GetComponentsInChildren <PointAtEnemy>().Length]; arrows = player.GetComponentsInChildren <PointAtEnemy>(); for (int i = 0; i < arrows.Length; i++) { Destroy(arrows[i].gameObject); } PointAtPortal[] arrowsPortal = new PointAtPortal[player.GetComponentsInChildren <PointAtPortal>().Length]; arrowsPortal = player.GetComponentsInChildren <PointAtPortal>(); for (int i = 0; i < arrowsPortal.Length; i++) { Destroy(arrowsPortal[i].gameObject); } }