// Update is called once per frame void Update() { if (Input.GetAxis("Horizontal") <= -0.9) { JoyLeftActive = true; } else { JoyLeftActive = false; } if (Input.GetAxis("Horizontal") >= 0.9) { JoyRightActive = true; } else { JoyRightActive = false; } if (Input.GetKeyDown(SprintButton)) { MovementSpeed = SetSpeed + SprintBoost; } if (Input.GetKeyUp(SprintButton)) { MovementSpeed = SetSpeed; } if (LeftKeyActive || RightKeyActive) { if (WalkAnimActive && !Anim.Active()) { Debug.Log("AnimStart"); Anim.PlayAnimation(0, AnimSpeed); } } PlayerRigid.velocity = new Vector2(Mathf.Clamp(PlayerRigid.velocity.x, -MovementSpeed, MovementSpeed), Mathf.Clamp(PlayerRigid.velocity.y, -9999, 6)); if (Input.GetKey(LeftButton) || JoyLeftActive) { LeftKeyActive = true; if (MovementActive && LeftMovementActive) { PlayerRigid.velocity = new Vector2(-MovementSpeed, PlayerRigid.velocity.y); } //Flips the sprite so that it reflects the direction the player is facing. PlayerRenderer.flipX = true; } else { LeftKeyActive = false; } if (Input.GetKey(RightButton) || JoyRightActive) { RightKeyActive = true; if (MovementActive && RightMovementActive) { PlayerRigid.velocity = new Vector2(MovementSpeed, PlayerRigid.velocity.y); } //Flips the sprite so that it reflects the direction the player is facing. PlayerRenderer.flipX = false; } else { RightKeyActive = false; } if (!LeftKeyActive && !RightKeyActive) { //Stops the player from moving (sliding due to physics) Anim.Stop(); PlayerRigid.velocity = new Vector2(0, PlayerRigid.velocity.y); if (CanJump) { PlayerRenderer.sprite = NormalSprite; } } if ((Input.GetKeyDown(JumpButton) || Input.GetButton("Jump")) && CanJump) { Anim.Stop(); WalkAnimActive = false; CanJump = false; PlayerRenderer.sprite = JumpSprite; PlayerRigid.AddForce(new Vector2(0, JumpForce)); } if (Left.Collided()) { LeftMovementActive = false; } else { LeftMovementActive = true; } if (Right.Collided()) { RightMovementActive = false; } else { RightMovementActive = true; } }