public void TakeDamage(int value) { live -= value; if (live <= 0) { GameManager.Instance.ClearEnemy(gameObject); GameManager.Instance.UpdateScore(score); if (dieEffect != null) { var newObj = Instantiate(dieEffect, transform.position, Quaternion.identity); Destroy(newObj, GameManager.effectDestroyTime); } if (isTyrant) { if (CurrentInvadeTyrant != null && CurrentInvadeTyrant == this) { CurrentInvadeTyrant = null; } } Destroy(gameObject); } }
private void Update() { switch (aiState) { case AiState.EarlySpawn: EarlySpawn(); break; case AiState.InWaitingPosition: InWaitingPosition(); break; case AiState.ReadyToInvade: ReadyToInvade(); break; case AiState.Launch: if (isTyrant) { CurrentInvadeTyrant = this; } Launch(); aiState = AiState.InvadePlayer; break; case AiState.InvadePlayer: InvadePlayer(); if (transform.position.y <= assaultPosY) { aiState = AiState.Assault; } break; case AiState.Assault: Assault(); if (transform.position.y < belowBorderY) { TeleportBack(); } break; } if (!ignoreSmoothRot) { SmoothRotate(); } }
/// <summary> /// While attacking and reach Y min position. Unit should comback to it's waiting pos. /// </summary> protected void TeleportBack() { if (waitingTrans != null) { var comebackPos = waitingTrans.position; var trueComebackPos = new Vector2(comebackPos.x, comebackPos.y + offsetYEnemyBack); transform.position = trueComebackPos; } if (isTyrant && CurrentInvadeTyrant == this) { CurrentInvadeTyrant = null; } SetAiState(BaseEnemyController.AiState.EarlySpawn); }