void Update() { // Animations if (m_aggro.isInCombat()) { m_anim.SetAnimation(Animation.ATTACK); } else if (m_groundCheck.isGrounded()) { m_anim.SetAnimation(Animation.WALK); } else { m_anim.SetAnimation(Animation.IDLE); } //Effects if (m_stats.getHp() == 0) { m_lastSeenHp = m_stats.getHp(); m_anim.SetEffect(Effect.DEATH); m_anim.PauseAnimation(); } else if (m_lastSeenHp > m_stats.getHp()) { m_lastSeenHp = m_stats.getHp(); m_anim.SetEffect(Effect.DAMAGE); } }
void Update() { // Attacking if (m_aggro.isInCombat() != null) { m_rb.constraints |= RigidbodyConstraints2D.FreezePositionX; } // Moving else if (m_groundCheck == null || m_groundCheck.isGrounded()) { m_rb.constraints &= ~RigidbodyConstraints2D.FreezePositionX; // Jump if (m_jumpForce > 0 && UnityEngine.Random.Range(0f, 1f) <= m_jumpChance && !is_jumping) { StartCoroutine(Jump()); } // Walk else { Vector2 dirToMove = m_aggro.getMovingDirection(); dirToMove = new Vector2(dirToMove.x * m_availableDir.x, dirToMove.y * m_availableDir.y).normalized *m_avgSpeed *UnityEngine.Random.Range(m_variance.x, m_variance.y); m_rb.velocity = (dirToMove + m_rb.velocity) / 2; } } // In the air - continue moving forward with no random else if (!m_groundCheck.isGrounded()) { Vector2 dirToMove = m_aggro.getMovingDirection(); dirToMove = new Vector2(dirToMove.x * m_availableDir.x, dirToMove.y * m_availableDir.y).normalized *m_avgSpeed *UnityEngine.Random.Range(m_variance.x, m_variance.y); m_rb.velocity = new Vector2((dirToMove.x + m_rb.velocity.x) / 2, m_rb.velocity.y + dirToMove.y); } //Flip facing dir if (m_aggro.getMovingDirection().x < 0) { transform.localScale = new Vector2(-1 * Mathf.Abs(transform.localScale.x), transform.localScale.y); } else { transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y); } }