public void finishShag() { SetPlayerEnabled(true); LevelDefinitionBehaviour.IncreaseBunniesByValue(babyCount == -1 ? LevelDefinitionBehaviour.BunnyReplenishmentRate : babyCount); player.Flip(); }
/// <summary> /// Update that is called on each frame. /// Handles jumping, the run button, and the wall colliders. /// </summary> protected void Update() { // after leaving a wall hug, you have a couple of frames to do a wall jump if (isTouchingLeftWall || isTouchingRightWall) { currentWallJumpGracePeriod = wallJumpGracePeriod; } else if (currentWallJumpGracePeriod > 0) { currentWallJumpGracePeriod--; } if (StaticConstants.AcceptPlayerInput) { // jumping if (Input.GetButtonDown(jumpButton)) { Jump(); } else if (Input.GetButton(jumpButton)) { ExtendJump(); } else if (Input.GetButtonUp(jumpButton)) { RestoreGravityScale(); } // running isRunning = maxRunSpeed != 0 && Input.GetButton(runButton); bool pressedBirthButton = Input.GetButtonDown(birthButton); bool enoughBunnies = LevelDefinitionBehaviour.GetBunniesLeft() > 0 || StaticConstants.FunModeActive; if ((pressedBirthButton || Input.GetKeyDown(KeyCode.Mouse0) || (Input.GetKey(KeyCode.Mouse0) && StaticConstants.FunModeActive)) && StaticConstants.AcceptPlayerInput && enoughBunnies) { Vector2 direction; if (pressedBirthButton) { direction = new Vector2(-Input.GetAxisRaw("Horizontal"), -Input.GetAxisRaw("Vertical")); } else { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); direction = (mousePos - this.transform.position); } if (direction == Vector2.zero) { direction.y = -1; } direction.Normalize(); Vector3 newBunnyPos = new Vector3(this.transform.position.x, this.transform.position.y + 0.4f, 0); GameObject newBunny = GameObject.Instantiate(bunnyPrefab, newBunnyPos, bunnyPrefab.transform.rotation); newBunny.GetComponent <Rigidbody2D>().velocity = direction * _bunnySpawnForce; this.GetComponent <Rigidbody2D>().velocity = -direction * _bunnySpawnKnockback; _eventManager.FireEvent(EventTypes.BunnySpawned, null); LevelDefinitionBehaviour.SetBunniesLeft(LevelDefinitionBehaviour.GetBunniesLeft() - 1); } } }