public void Update() { ListReadOnly <EnemyComponent> enemyComponents = entityDatabase.QueryTypes <EnemyComponent>(); if (enemyComponents.Count == 0) { return; } Entity playerEntity = entityDatabase.QueryEntity <PlayerComponent>(); GameObject playerObject = playerEntity.GetComponent <TransformComponent>().transform.gameObject; var enumerator = enemyComponents.GetEnumerator(); while (enumerator.MoveNext()) { EnemyComponent enemyComponent = enumerator.Current; enemyComponent.attackTimer += Time.deltaTime; if (enemyComponent.attackTimer >= enemyComponent.enemyDO.timeBetweenAttacks && enemyComponent.trigger.isColliding(playerObject) && enemyComponent.currentHealth > 0) { Attack(enemyComponent, playerEntity); } if (playerEntity.HasTag(Tag.Dead)) { enemyComponent.anim.SetTrigger("PlayerDead"); } } }
public void Update() { ListReadOnly <EnemyComponent> enemyComponents = entityDatabase.QueryTypes <EnemyComponent>(); if (enemyComponents.Count == 0) { return; } Entity playerEntity = entityDatabase.QueryEntity <PlayerComponent>(); Transform playerTransform = playerEntity.GetComponent <TransformComponent>().transform; var enumerator = enemyComponents.GetEnumerator(); while (enumerator.MoveNext()) { EnemyComponent enemyComponent = enumerator.Current; if (enemyComponent.currentHealth > 0 && !playerEntity.HasTag(Tag.Dead)) { enemyComponent.nav.SetDestination(playerTransform.position); } else { enemyComponent.nav.enabled = false; } } }
public void Update() { ListReadOnly <EnemySpawnerComponent> enemySpawnerComponents = entityDatabase.QueryTypes <EnemySpawnerComponent>(); var enumerator = enemySpawnerComponents.GetEnumerator(); while (enumerator.MoveNext()) { EnemySpawnerComponent enemySpawnerComponent = enumerator.Current; enemySpawnerComponent.timer -= Time.deltaTime; if (enemySpawnerComponent.timer <= 0) { Spawn(enemySpawnerComponent.spawnerData); enemySpawnerComponent.timer = enemySpawnerComponent.spawnerData.spawnTime; } } }