// Start is called before the first frame update void Start() { myGameOverOverlay = FindObjectOfType <GameOverOverlay>(); pauseScreen = GameObject.FindGameObjectWithTag("PauseScreen"); originalTimeScale = 1; isPaused = false; }
//Method to remove the game ovr overlay from the screen public void RemoveGameOverOverlay(GameOverOverlay o, Canvas c) { //Remove overlay objects from the screen c.Children.Remove(o.background); c.Children.Remove(o.GameOverSprite); c.Children.Remove(o.again); c.Children.Remove(o.menu); }
void Start() { instance = this; finalScore = GameObject.Find("finalScore_label").GetComponent <Text>(); goToMenu = GameObject.Find("goToMenu_label").GetComponent <Text>(); gameOver_label = GameObject.Find("gameOver_label").GetComponent <Text>(); yourScore_label = GameObject.Find("yourScore_label").GetComponent <Text>(); toggleOverlay(false); }
public void GameOver() { FreezePlayer = true; GameLost = true; GameWon = false; gameOverOverlay = new GameOverOverlay(); gameOverOverlay.againIsPressed += OnPressedOnRestart; gameOverOverlay.pressedOnMenu += OnPressedOnMenu; AddGameOverOverlay(gameOverOverlay, GameCanvas); playing = false; GameTimer.countdownTimer.Stop(); //check if explosion will take place so it can be deleted and not shown on screen if (explosionIsGoingToTakePlace) { ExplosionEnded(); } }
public void OnPressedOnRestart(object source, EventArgs e) { PlayAgain(); if (pauseOverlay != null) { RemovePauseOverlay(pauseOverlay, GameCanvas); pauseOverlay = null; } else if (gameOverOverlay != null) { RemoveGameOverOverlay(gameOverOverlay, GameCanvas); gameOverOverlay = null; } else { RemoveGameWonOverlay(gameWonOverlay, GameCanvas); gameWonOverlay = null; } }
//Method to add game over overlay public void AddGameOverOverlay(GameOverOverlay o, Canvas c) { //Create audio player to play sound effect on game over SoundPlayer audio = new SoundPlayer(Properties.Resources.game_over_sound_effect); audio.Play(); //create background worker to sync audio playback with overlay var backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += (s, e) => { Thread.Sleep(150); }; backgroundWorker.RunWorkerCompleted += (s, e) => { //Add everything to the screen Canvas.SetTop(o.background, o.backgroundY); Canvas.SetLeft(o.background, o.backgroundX); c.Children.Add(o.background); Panel.SetZIndex(o.background, 99); Canvas.SetTop(o.GameOverSprite, o.GameOverSpriteY); Canvas.SetLeft(o.GameOverSprite, o.GameOverSpriteX); c.Children.Add(o.GameOverSprite); Panel.SetZIndex(o.GameOverSprite, 99); Canvas.SetTop(o.again, o.againY); Canvas.SetLeft(o.again, o.againX); c.Children.Add(o.again); Panel.SetZIndex(o.again, 99); Canvas.SetTop(o.menu, o.menuY); Canvas.SetLeft(o.menu, o.menuX); c.Children.Add(o.menu); Panel.SetZIndex(o.menu, 99); }; backgroundWorker.RunWorkerAsync(); }
protected override void Awake() { base.Awake(); combatantHudLeft = GetComponentsInChildren <CombatantHUD>()[0]; combatantHudRight = GetComponentsInChildren <CombatantHUD>()[1]; _roundTransitionText = GetComponentInChildren <LayeredText>(); _roundTransitionAnimator = _roundTransitionText.GetComponent <Animator>(); inventoryInterface = GetComponentInChildren <InventoryInterface>(true); commandInterface = GetComponentInChildren <CommandInterface>(true); queueInterface = GetComponentInChildren <CommandQueueInterface>(); lootInterface = GetComponentInChildren <LootInterface>(); itemDescriptionPanel = GetComponentInChildren <ItemDescriptionPanel>(); inputInfoInterface = GetComponentInChildren <InputInfoInterface>(); inventoryInterface.Show(false); lootInterface.Show(false); itemDescriptionPanel.gameObject.SetActive(false); _cameraController = FindObjectOfType <CameraController>(); _gameOverOverlay = GetComponentInChildren <GameOverOverlay>(true); }
// Update is called once per frame void Update() { if (currentState == GameState.Playing) { if (powerUpTimer > powerUPTime) { GeneratePowerUps(); powerUpTimer = 0.0f; } else { powerUpTimer += Time.deltaTime; } int loseCount = 0; foreach (Player player in players) { if (player.gameOverTimer > gameOverTime) { if (!player.isGameOver) { player.AnimateDead(); player.isGameOver = true; Debug.Log("Player " + player.playerIndex + " lose!!"); } } if (player.isGameOver) { loseCount++; } } if (loseCount >= players.Count - 1) { Player winningPlayer = null; foreach (Player player in players) { if (!player.isGameOver) { winningPlayer = player; } } currentState = GameState.End; gameOverOverlay = Instantiate(gameOverOverlayPrefab); gameOverOverlay.transform.SetParent(HUDCanvas.transform); gameOverOverlay.transform.localPosition = Vector3.zero; GameOverOverlay overlay = gameOverOverlay.GetComponent <GameOverOverlay>(); if (winningPlayer == null) { overlay.nameText.text = "No Body"; overlay.headLogo.gameObject.SetActive(false); } else { overlay.nameText.text = "Player " + winningPlayer.playerIndex; overlay.headLogo.sprite = winningPlayer.HUD.headLogos[winningPlayer.playerIndex]; } overlay.restartDelegate = delegate() { SceneManager.LoadScene(1); // Destroy(gameOverOverlay); // StartNewGame(); }; } } }