// Update is called once per frame void Update() { if (input == null || m_isDead) { return; } //Check if character just landed on the ground if (!m_grounded && m_groundSensor.State()) { m_grounded = true; m_animator.SetBool("Grounded", m_grounded); LandedEvent(); } //Check if character just started falling if (m_grounded && !m_groundSensor.State()) { m_grounded = false; m_animator.SetBool("Grounded", m_grounded); } // -- Handle input and movement -- var inputX = CanMove() ? input.GetHorizontalMove() : 0; // Swap direction of sprite depending on walk direction if (inputX > 0) { transform.localScale = new Vector3(-1.0f, 1.0f, 1.0f); } else if (inputX < 0) { transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); } // Move m_body2d.velocity = new Vector2(inputX * m_speed, m_body2d.velocity.y); //Set AirSpeed in animator m_animator.SetFloat("AirSpeed", m_body2d.velocity.y); if (postAttackCooldown > 0) { postAttackCooldown -= Time.deltaTime; } if (blockTimer <= 0 && postBlockCooldown > 0) { postBlockCooldown -= Time.deltaTime; IsBlocking = false; m_combatIdle = false; } if (blockTimer > 0) { blockTimer -= Time.deltaTime; } // -- Handle Animations -- //Attack else if (input.Attack() && postAttackCooldown <= 0) { m_animator.SetTrigger("Attack"); postAttackCooldown = 0.9f; AttackedEvent(); } //Jump else if (input.Jump() && m_grounded) { m_animator.SetTrigger("Jump"); m_grounded = false; m_animator.SetBool("Grounded", m_grounded); m_body2d.velocity = new Vector2(m_body2d.velocity.x, m_jumpForce); m_groundSensor.Disable(0.2f); JumpedEvent(); } else if (input.Block() && postBlockCooldown <= 0) { IsBlocking = true; m_combatIdle = true; postBlockCooldown = 1f; blockTimer = blockDuration; } //Run if (Mathf.Abs(inputX) > Mathf.Epsilon) { m_animator.SetInteger("AnimState", 2); } //Combat Idle else if (m_combatIdle) { m_animator.SetInteger("AnimState", 1); } //Idle else { m_animator.SetInteger("AnimState", 0); } }