void OnTriggerEnter2D(Collider2D other) { if (isActive) { // Play the barrier sound AudioSource audio = GetComponent <AudioSource>(); audio.Play(); // Give the player a new power-up // Choose random powerup int powerUpId = PowerUp.getRandomPowerUp(); PowerUp powerUp; Debug.Log("Power-up: " + powerUpId); switch (powerUpId) { case 1: powerUp = new BlinkBall(other.GetComponent <Ball>(), Constants.BALL_BLINK_INTERVAL); break; case 2: powerUp = new ResizePaddle(GameObject.FindGameObjectWithTag("player_1_paddle").GetComponent <Paddle>(), (Paddle)GameObject.FindGameObjectWithTag("player_2_paddle").GetComponent <Paddle>(), Constants.POWER_UP_PADDLE_RESIZE); break; default: powerUp = new BlinkBall(other.GetComponent <Ball>(), Constants.BALL_BLINK_INTERVAL); break; } Vector2 velocity = other.GetComponent <Rigidbody2D>().velocity; if (velocity.y > 0) { // Give the player the chosen power-up StartCoroutine(powerUp.apply(1)); } else if (velocity.y < 0) { // Give the player the chosen power-up StartCoroutine(powerUp.apply(2)); } // Hide barrier hide(); GameLogic.hasBarrier = false; StartCoroutine(GameLogic.setBarrierDelay(gameObject, audio.clip.length)); } }
public override void UpdatePlaying() { shootTimer += Time.deltaTime; bindings = InputManager._instance.bindings; if (bindings.pauseGame.WasPressed) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; Globals.gameState = GameState.Paused; } if (playerState == inputState.free) { move.MovePlayer(new Vector3(bindings.move.X, 0, bindings.move.Y)); if (bindings.fire.IsPressed && shootTimer > 0.25 && !weapon.charging) { if (CheckWallDistance()) { weapon.PrepareToFire(); } } if (bindings.fire.WasReleased && weapon.charging) { if (CheckWallDistance()) { blinkBall = weapon.Fire(); weapon.charging = false; } } if (bindings.blink.IsPressed) { if (blinkBall != null) { blinkBall.SetPlayer(gameObject); } //peeking = true; } if (bindings.blink.WasReleased) { if (blinkBall != null) { shootTimer = 0; //peeking = false; weapon.GetComponentInChildren <SkinnedMeshRenderer> ().enabled = true; blinkBall.Teleport(gameObject); } else { // Play an error sound or something; } } if (Input.GetKeyDown(KeyCode.V)) { if (QualitySettings.vSyncCount != 0) { QualitySettings.vSyncCount = 0; } else { QualitySettings.vSyncCount = 1; } } } move.CameraMove(new Vector3(-bindings.look.Y, bindings.look.X, 0)); if (bindings.ragdoll.WasPressed) { Debug.Log("Ragdoll toggle"); if (playerState == inputState.free) { playerState = inputState.ragdoll; ragdoll.Activate(); } else { playerState = inputState.free; ragdoll.Deactivate(); } } if (bindings.respawn.WasPressed) { Die(); } }