IEnumerator MoveVillanTask() { transform.eulerAngles = new Vector3(0, -180, 0); rigidBody.gravityScale = 0; rigidBody.velocity = new Vector2(6f, 0); animator.SetBool("ToWalk", true); yield return(new WaitForSeconds(1.3f)); rigidBody.gravityScale = 2; animator.SetBool("ToWalk", false); music.Jump(); animator.SetBool("ToJump", true); rigidBody.velocity = new Vector2(6f, 16f); yield return(new WaitForSeconds(2)); music.Jump(); rigidBody.velocity = new Vector2(-6, 16f); yield return(new WaitForSeconds(2)); music.Jump(); rigidBody.velocity = new Vector2(-6, 16f); yield return(new WaitForSeconds(2)); music.Jump(); rigidBody.velocity = new Vector2(0, 16f); yield return(new WaitForSeconds(1)); animator.SetBool("ToJump", false); isAnimation = true; transform.position = new Vector3(-218, 268.5f, 0); transform.localScale = new Vector3(0.8f, 0.8f, 1); }
// Update is called once per frame void Update() { if (!VillanController.isAnimation || !canMove || PauseMenu.GameIsPaused) { return; } //animator state variables animator.SetFloat("Speed", Mathf.Abs(moveInput)); animator.SetBool("Grounded", grounded); animator.SetBool("Falling", false); animator.SetBool("SpacePressed", spacePressed); animator.SetBool("DownScene", inDownScene); inDownScene = CameraControler.change; grounded = IsGrounded(); // physic change in level 3 if (inDownScene) { rigidBody.velocity = new Vector2(0, -4f); rigidBody.gravityScale = 0.0f; } // back to physic from other levels if (!inDownScene) { rigidBody.gravityScale = 2f; } //jump if (grounded && Input.GetButtonUp("Jump") && !inDownScene && !animator.GetCurrentAnimatorStateInfo(0).IsName("FarmerFall")) { audio.Jump(); rigidBody.velocity = Vector2.up * jumpForce; ScoreScript.jumpCount++; jumpForce = 3; } //falling control if (grounded && isFalling) { audio.Fall(); animator.SetBool("Falling", true); isFalling = false; ScoreScript.fallNumber++; } if (rigidBody.velocity.y < -20 && !inDownScene) { isFalling = true; } //player flipping if (moveInput > 0 && !isFacingRight) { Flip(); } else if (moveInput < 0 && isFacingRight) { Flip(); } }