private void Awake() { AnimController = GetComponent(); } void Update() { horizontal = Input.GetAxisRaw("Horizontal"); if (Input.GetButtonDown("Jump") && IsGrounded()) { AnimController.SetTrigger("Jump"); Rbody.velocity = new Vector2(Rbody.velocity.x, jumpingPower); } if(Input.GetButtonUp("Jump") && Rbody.velocity.y > 0f) { AnimController.SetTrigger("Jump"); Rbody.velocity = new Vector2(Rbody.velocity.x, Rbody.velocity.y * 0.5f); } Flip(); } private void FixedUpdate() { Rbody.velocity = new Vector2(horizontal * speed, Rbody.velocity.y); if (Rbody.velocity.y < 0f) { if (!AnimController.GetBool("Falling")) AnimController.SetBool("Falling", true); } else { if (AnimController.GetBool("Falling")) AnimController.SetBool("Falling", false); } if (Rbody.velocity.x > 0.01f) { if (!AnimController.GetBool("Running")) AnimController.SetBool("Running", true); } else { if (AnimController.GetBool("Running")) AnimController.SetBool("Running", false); } } private bool IsGrounded() { return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer); } private void Flip() { if(isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f) { isFacingRight = !isFacingRight; Vector3 localScale = transform.localScale; localScale.x *= -1f; transform.localScale = localScale; } }