/// <summary> /// This fucntion spawns an instance of a hostage GO on the ySpawn pathway /// </summary> /// <param name="ySpawn">The pathway to be spawned</param> private void SpawnHostage(float ySpawn) { Vector3 spawnPosition = new Vector3(OffscreenX, ySpawn + FirstY, 0); Quaternion spawnDirection = Quaternion.identity; Instantiate(Hostages[_currentHostage], spawnPosition, spawnDirection); _currentHostageGo = GameObject.FindWithTag("Hostage"); _hostage = _currentHostageGo.GetComponent <HostageBehaviour>(); _hostage.HostagePosition = FirstHostagePosition.transform.position + (Vector3.left * (_currentHostage)); _currentHostageGo.gameObject.GetComponent <SpriteRenderer>().sortingOrder = SetSortingOrder(ySpawn); _hostageAppeared = true; _currentHostage++; }
private void UpdateGameLogic() { if (SavedHostages + DeadHostages == _maxHostages) //Checks for winning condition, at least one hostage saved { _currentHostageGo.gameObject.transform.localScale = new Vector3(1, 1, 1); Time.timeScale = 0; if (SavedHostages == _maxHostages) { WinText.enabled = true; } else if (DeadHostages == _maxHostages) { GameOverText.enabled = true; RestartButton.gameObject.SetActive(true); WaveText.enabled = false; Time.timeScale = 0; } else { BadEndingText.enabled = true; } WaveText.enabled = false; _finished = true; RestartButton.gameObject.SetActive(true); } else if (Bullets == 0) // Checks for losing condition, no hostage saved or no bullets left { GameOverText.enabled = true; RestartButton.gameObject.SetActive(true); WaveText.enabled = false; Time.timeScale = 0; _finished = true; } if (NumberGuards == 0 && _hostageAppeared) { _hostage = _currentHostageGo.GetComponent <HostageBehaviour>(); _hostage.SaveHostage(); _hostageAppeared = false; } }