public IEnumerator Attack(int phase) { if (attacks.ContainsKey(phase)) { BossAttack attack = attacks[phase][Random.Range(0, attacks[phase].Count)]; yield return(StartCoroutine(attack.Attack())); } else { Debug.unityLogger.Log("Boss cannot attack because are no attacks in this phase."); } }
private void FixedUpdate() { if (enemyHealth.dead || player == null) { return; } currentPath = destination.Value.position; ladderPath = null; FindPath(ladders); maxVelosity = isAggressive ? maxRunVelosity : maxWalkVelosity; rigBody.AddForce(Vector2.right * moveForce * Mathf.Sign( ladderPath != null ? ladderPath.transform.position.x - transform.position.x : destination.Value.position.x - transform.position.x)); if (Mathf.Abs(rigBody.velocity.x) > maxVelosity) { rigBody.velocity = new Vector2(Mathf.Sign(rigBody.velocity.x) * maxVelosity, rigBody.velocity.y); } anim.SetFloat("VelosityX", Mathf.Abs(rigBody.velocity.x)); anim.SetFloat("VelosityY", Mathf.Abs(rigBody.velocity.y)); if (rigBody.velocity.x < 0 == transform.localScale.x > 0) { enemyHealth.Flip(); } RaycastHit2D hit = Physics2D.Linecast(transform.position, new Vector2(transform.position.x + Mathf.Sign(rigBody.velocity.x) * detectionRange, transform.position.y), LayerMask.GetMask("Player")); if (hit.collider != null) { isAggressive = true; destination = new LinkedListNode <Transform>(player.transform); lastAggressionTime = Time.time; rigBody.velocity = Vector2.Lerp(rigBody.velocity, Vector2.zero, 0.99f); bossAttack.Attack(); } }
// Update is called once per frame void Update() { playerTransform = tPlayer.transform; float distance = Vector3.Distance(playerTransform.position, transform.position); if (distance <= fAlertRad) { nAgent.SetDestination(playerTransform.position); aEnemyAnim.SetInteger("Walk Forward", 1); if (nAgent.remainingDistance < 7f) { aEnemyAnim.SetInteger("Walk Forward", 0); bossAttack.Attack(); } FaceTarget(); } else { nAgent.SetDestination(transform.position); } }