private void OnDisable() { if (Instance == this) { Instance = null; } }
private void OnEnable() { if (Instance == null) { Instance = this; } else if (Instance != this) { Debug.Log("A tank spawner already exists. Destroying new instance."); Destroy(this.gameObject); } }
public MapCreator(Settings settings, MapParser mapParser, MapObjectsManager mapObjectsManager, TankSpawner tankSpawner, BonusSpawner bonusSpawner, MapSettingsManager mapSettingsManager) { _settings = settings; _mapParser = mapParser; _mapObjectsManager = mapObjectsManager; _tankSpawner = tankSpawner; _bonusSpawner = bonusSpawner; _mapSettingsManager = mapSettingsManager; }
private void OnDeath() { if (tag == "Enemy") { TankSpawner spTank = Object.FindObjectOfType <TankSpawner>(); spTank.spawnTank(); TankShooting giveBomb = Object.FindObjectOfType <TankShooting>(); giveBomb.m_bombCount++; } // Set the flag so that this function is only called once m_Dead = true; // Move the instantiated explosion prefab to the tank's position and turn it on m_ExplosionParticles.transform.position = transform.position; m_ExplosionParticles.gameObject.SetActive(true); // play the particle system of the tank exploding m_ExplosionParticles.Play(); // Turn the tank off gameObject.SetActive(false); }
// Start is called before the first frame update void Start() { spawner = GetComponent <TankSpawner>(); EditedTank.PopulateSavedScriptDropdown(scriptChoise); EditedTank.toRepopulate.Add(scriptChoise); sideChoise.options.Clear(); foreach (var item in spawner.spawnpoints) { sideChoise.options.Add(new Dropdown.OptionData(item.sideId.ToString())); } sideChoise.value = -1; sideChoise.value = 0; add.onClick.AddListener(() => { var code = EditedTank.LoadScript(scriptChoise.options[scriptChoise.value].text, new Tank.DummyLogger()); if (!string.IsNullOrEmpty(code)) { spawner.Spawn(int.Parse(sideChoise.options[sideChoise.value].text), code); } }); }
public void OnNewGame() { m_gameTime = 0; m_GameState = GameState.Playing; m_MessageText.text = ""; m_BombCountNum.gameObject.SetActive(true); m_BombCountText.gameObject.SetActive(true); m_ScoreNum.gameObject.SetActive(true); m_ScoreText.gameObject.SetActive(true); m_TimerNum.gameObject.SetActive(true); m_TimerText.gameObject.SetActive(true); m_FinalScore.gameObject.SetActive(false); m_NewGameButton.gameObject.SetActive(false); m_HighScoresButton.gameObject.SetActive(false); foreach (GameObject tank in m_Tanks) { tank.SetActive(false); } foreach (Bomb bomb in FindObjectsOfType <Bomb>()) { bomb.Kill(); } m_Tanks.RemoveRange(0, m_Tanks.Count); m_Tanks.Add(m_PlayerTank); m_Tanks[0].SetActive(true); m_PlayerTank.transform.position = new Vector3(0, 0, 0); m_PlayerTank.transform.rotation = new Quaternion(0, 0, 0, 0); TankSpawner spTank = Object.FindObjectOfType <TankSpawner>(); spTank.spawnTank(); if (ScoreTabToggle == true) { m_HighScorePanel.gameObject.SetActive(false); ScoreTabToggle = false; } }
private void Update() { switch (m_GameState) { case GameState.Start: if (Input.GetKeyUp(KeyCode.Return) == true) { m_BombCountNum.gameObject.SetActive(true); m_BombCountText.gameObject.SetActive(true); m_ScoreNum.gameObject.SetActive(true); m_ScoreText.gameObject.SetActive(true); m_TimerNum.gameObject.SetActive(true); m_TimerText.gameObject.SetActive(true); m_lowHealthEdge.gameObject.SetActive(true); m_MessageText.text = ""; m_GameState = GameState.Playing; for (int i = 0; i < m_Tanks.Count; i++) { m_Tanks[i].SetActive(true); } TankSpawner spTank = Object.FindObjectOfType <TankSpawner>(); spTank.spawnTank(); } break; case GameState.Playing: //if(m_Tanks.Contains(m_PlayerTank) == false) //{ //} bool isGameOver = false; m_gameTime += Time.deltaTime; int seconds = Mathf.RoundToInt(m_gameTime); m_TimerNum.text = string.Format("{0:D2}:{1:D2}", (seconds / 60), (seconds % 60)); m_Score = Mathf.RoundToInt(0 + (m_gameTime * (m_Tanks.Count - 1))); m_ScoreNum.text = m_Score.ToString(); if (IsPlayerDead() == true) { isGameOver = true; } if (isGameOver == true) { m_GameState = GameState.GameOver; m_BombCountNum.gameObject.SetActive(false); m_BombCountText.gameObject.SetActive(false); m_ScoreNum.gameObject.SetActive(false); m_ScoreText.gameObject.SetActive(false); m_TimerNum.gameObject.SetActive(false); m_TimerText.gameObject.SetActive(false); m_FinalScore.gameObject.SetActive(true); m_lowHealthEdge.gameObject.SetActive(false); m_NewGameButton.gameObject.SetActive(true); m_HighScoresButton.gameObject.SetActive(true); if (ScoreTabToggle == true) { m_HighScorePanel.gameObject.SetActive(false); ScoreTabToggle = false; } m_Score = Mathf.RoundToInt(0 + (m_gameTime * (m_Tanks.Count - 1))); m_MessageText.text = "Your final score is:"; m_FinalScore.text = m_Score.ToString(); //save the score m_HighScores.AddScore(m_Score); m_HighScores.SaveScoresToFile(); } else { TankShooting countBomb = Object.FindObjectOfType <TankShooting>(); m_BombCountNum.text = countBomb.m_bombCount.ToString(); } break; case GameState.GameOver: if (Input.GetKeyUp(KeyCode.Return) == true) { m_gameTime = 0; m_GameState = GameState.Playing; m_MessageText.text = ""; m_BombCountNum.gameObject.SetActive(true); m_BombCountText.gameObject.SetActive(true); m_ScoreNum.gameObject.SetActive(true); m_ScoreText.gameObject.SetActive(true); m_TimerNum.gameObject.SetActive(true); m_TimerText.gameObject.SetActive(true); m_FinalScore.gameObject.SetActive(false); m_NewGameButton.gameObject.SetActive(false); m_HighScoresButton.gameObject.SetActive(false); foreach (GameObject tank in m_Tanks) { tank.SetActive(false); } foreach (Bomb bomb in FindObjectsOfType <Bomb>()) { bomb.Kill(); } m_Tanks.RemoveRange(0, m_Tanks.Count); m_Tanks.Add(m_PlayerTank); m_Tanks[0].SetActive(true); m_PlayerTank.transform.position = new Vector3(0, 0, 0); m_PlayerTank.transform.rotation = new Quaternion(0, 0, 0, 0); TankSpawner spTank = Object.FindObjectOfType <TankSpawner>(); spTank.spawnTank(); } break; } if (Input.GetKeyUp(KeyCode.Escape)) { Application.Quit(); } if ((Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.Tab)) && ScoreTabToggle == true) { m_HighScorePanel.gameObject.SetActive(false); } }
private void Construct(MapCreator mapCreator, TankSpawner tankSpawner) { _mapCreator = mapCreator; _tankSpawner = tankSpawner; }