public void GameOver() { if (controlType == ControlType.Autoplay) { LevelInstance.GetInstance().SaveStats(false); } gameOver = true; lastLevelPlayed = SceneManager.GetActiveScene().buildIndex; SceneManager.LoadScene(SceneManager.sceneCountInBuildSettings - 1); }
void Awake() { if (levelType == LevelType.StartScreen) { GameInstance.GetInstance().SetControlType(controlType); if (controlType == ControlType.Mouse) { Cursor.lockState = CursorLockMode.Confined; } } else { controlType = GameInstance.GetInstance().GetControlType(); } GameInstance.GetInstance(gameInstancePrefab); if (levelType == LevelType.Playable) { LevelInstance.GetInstance(levelInstancePrefab); if (!FindObjectOfType <TextMeshProUGUI>()) { if (gameCanvasPrefab == null) { Object.Instantiate(Resources.Load("Prefabs/Game Canvas"), Vector2.zero, Quaternion.identity); } else { Object.Instantiate(gameCanvasPrefab, Vector2.zero, Quaternion.identity); } } } else if (levelType == LevelType.StartScreen) { GameInstance.GetInstance().ResetGame(); GameInstance.GetInstance().SetGameSpeed(gameSpeed); if (controlType == ControlType.Autoplay) { Invoke("StartRandomLevel", 1f); } } else if (levelType == LevelType.GameOver) { if (controlType == ControlType.Autoplay) { Invoke("RestartGame", 1f); } } if (controlType == ControlType.Autoplay) { AudioListener.volume = 0; GameInstance.GetInstance().SetScore(0); } }
private void OnDestroy() { if (gameInstance && levelInstance && !gameInstance.IsGameOver() && levelInstance.BreakBlock() <= 0 && !levelInstance.IsGameWon()) { levelInstance.SetGameWon(); if (gameInstance.GetControlType() == ControlType.Autoplay) { LevelInstance.GetInstance().SaveStats(true); } gameInstance.LoadNextScene(); } }
void Start() { health = startingHealth; levelInstance = LevelInstance.GetInstance(); gameInstance = GameInstance.GetInstance(); if (gameObject.tag == breakableBlockTag) { LevelInstance.GetInstance().AddBlock(); } if (transform.childCount > 0 && transform.GetChild(0).gameObject.tag == "Ball") { trappedBall = transform.GetChild(0).gameObject; } }
void DestroyBlock() { GameObject newBall; Rigidbody2D rb = GetComponent <Rigidbody2D>(); rb.bodyType = RigidbodyType2D.Dynamic; SpriteRenderer sr = GetComponent <SpriteRenderer>(); sr.color = new Color(sr.color.r, sr.color.g, sr.color.b, 0.1f); GetComponent <BoxCollider2D>().isTrigger = true; rb.AddForce(Vector2.down * 20f, ForceMode2D.Impulse); LevelInstance.GetInstance().AddScore(pointValue); if (trappedBall) { newBall = Instantiate(ballPrefab); newBall.GetComponent <Ball>().isBallInPlay = true; newBall.transform.position = trappedBall.transform.position; Destroy(trappedBall); trappedBall = null; } if (exploding) { PlayDamageEffect(true); foreach (Block b in FindObjectsOfType <Block>()) { if (b.gameObject != gameObject) { float r = (b.transform.position - transform.position).magnitude; if (r < explosionRadius) { b.DamageBlock(explosionRadius / (r + .01f) * 100, r); } } } Destroy(gameObject); } }