// Use this for initialization void Awake() { if (instance == null) { instance = this; } else { Destroy(this); } }
// ============================================= Methods // Start is called before the first frame update void Start() { // Spawn a player SpawnPlayer(); // Get the player, if not set if (player == null) { player = FindObjectOfType <PlayerController>().gameObject; } // Set the audiosource if (audioSource == null) { audioSource = GetComponent <AudioSource>(); } // Get the title event manager and attempt to get some info titleEventManager = FindObjectOfType <TitleEventManager>(); if (titleEventManager != null) { difficulty = titleEventManager.difficulty; } // Set the event text if (eventText == null) { eventText = GameObject.Find("Event Text").GetComponent <TMP_Text>(); } eventText.text = ""; // Set the BGM audioSource.clip = bGM; audioSource.loop = true; audioSource.volume = 0.35f; audioSource.Play(); // Get the spawn locations and spawn enemies enemySpawnLocations = GameObject.FindGameObjectsWithTag("EnemySpawn"); for (int i = 0; i < numOfEnemies; i++) { SpawnEnemy(); } // Get the spawn locations and spawn player AIs playerSpawnLocations = GameObject.FindGameObjectsWithTag("PlayerSpawn"); for (int i = 0; i < numOfPlayerAIs; i++) { SpawnPlayerAI(); } // Set UI elements if (gameUI == null) { gameUI = GameObject.Find("Game UI").GetComponent <Canvas>(); } if (healthBar == null) { healthBar = gameUI.transform.Find("Health Bar").transform.Find("Health Bar Foreground").gameObject; } if (ammoCounter == null) { ammoCounter = gameUI.transform.Find("Bullet Counter").gameObject; } ammoCounter.SetActive(false); // Re-hide the pause screen if (pauseScreen == null) { pauseScreen = GameObject.Find("Pause UI"); } pauseScreen.SetActive(false); // Spawn some guns for the player SpawnGuns(); // Set player references SetPlayerReferences(player); }