public void CreateNewBall() { var ball = Instantiate(BallPrefab); ball.transform.position = _paddleAnchor.transform.GetChild(0).transform.position; ball.transform.position += new Vector3(0, 0.25f, 0); ball.GetComponent <CircleCollider2D>().enabled = false; // Create initial event text _eventManager.CreateEvent("Tap Twice"); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { StopGame(); } if (!IsStarted) { StartGame(); } #region Editor stuff #if UNITY_EDITOR if (Input.GetKeyUp(KeyCode.Return)) { AddScore(100000); } if (Input.GetKeyUp(KeyCode.Escape) && !IsPaused) { TogglePause(); } if (Input.GetKeyUp(KeyCode.Tab)) { //var ring = _brickRings[0]; //foreach (Transform brick in ring.Anchor.transform) // brick.gameObject.SetActive(false); //CheckRings(); _paddleManager.WidenPaddles(); } #endif #endregion //if (SystemInfo.deviceType == DeviceType.Handheld) //{ // // Invert the z and w of the gyro attitude // var rotation = Input.gyro.attitude; // Physics.gravity = rotation * new Vector3(0, 1, 0); //} switch (_currentState) { case -1: // Switch to lost screen StopGame(); break; case 1: // Switch to won screen StopGame(); break; } if (IsPaused) { return; } // Update score if (_actualPointScore != _textPointScore) { _textPointScore += Mathf.CeilToInt((_actualPointScore - _textPointScore) / 2f); _scoreText.text = GameVariablesScript.ConvertScoreToString(_textPointScore); Debug("Hi"); } // Update time if (TimerStarted) { #region Timer Text _timer += Time.smoothDeltaTime; var minutes = Mathf.Floor(_timer / 60); var seconds = (_timer % 60); _timeText.text = minutes.ToString("00") + ":" + seconds.ToString("00"); #endregion #region Ball Speed Increase // Update the timer that increases ball speed _speedIncreaseTimer += Time.smoothDeltaTime; if (!_eventCreated && _speedIncreaseTimer > TimeForSpeedIncrease - TimeForSpeedIncreaseEvent) { _eventManager.CreateEvent("+", TimeForSpeedIncreaseEvent, 1); _eventCreated = true; } else if (_speedIncreaseTimer >= TimeForSpeedIncrease) { IncreaseBallSpeed(); _speedIncreaseTimer = 0; _eventCreated = false; } #endregion } #region Camera Shake if (_isCameraShaking) { UpdateShake(); } #endregion #region Combo if (_comboText.enabled) { _comboTimer += Time.smoothDeltaTime; _comboText.transform.localScale = Vector3.Lerp(ComboTextInitialScale, ComboTextFinalScale, _comboTimer / TimeForComboTextShow * 2); if (_comboText.transform.localScale.x > 1) { _comboText.transform.localScale = new Vector3(1, 1, 1); } if (_comboTimer > TimeForComboTextShow) { _comboTimer = 0; _comboText.enabled = false; } } #endregion #region Background Colour Shift var colour = _backgroundImage.color; switch (_backgroundColourIndex) { case 0: colour.r += BackgroundColourChangeSpeed / 255f; if (colour.r >= 1) { _backgroundColourIndex++; } break; case 1: colour.b -= BackgroundColourChangeSpeed / 255f; if (colour.b <= 0) { _backgroundColourIndex++; } break; case 2: colour.g += BackgroundColourChangeSpeed / 255f; if (colour.g >= 1) { _backgroundColourIndex++; } break; case 3: colour.r -= BackgroundColourChangeSpeed / 255f; if (colour.r <= 0) { _backgroundColourIndex++; } break; case 4: colour.b += BackgroundColourChangeSpeed / 255f; if (colour.b >= 1) { _backgroundColourIndex++; } break; case 5: colour.g -= BackgroundColourChangeSpeed / 255f; if (colour.g <= 0) { _backgroundColourIndex = 0; } break; } _backgroundImage.color = colour; #endregion }