// Start is called before the first frame update void Start() { gameoverLock = false; playerList = GameObject.FindGameObjectsWithTag("Player"); if (playerList.Length <= 0) { Debug.LogWarning("GameManager Cannot Find Any Players!"); } //Filter which player is which for (int i = 0; i < playerList.Length; i++) { if (playerList[i].GetComponent <PlayerController>().playerType == PlayerController.PLAYER.PLAYER1) { players.Add(playerList[i]); i = 0; } if (playerList[i].GetComponent <PlayerController>().playerType == PlayerController.PLAYER.PLAYER2 && players.Count == 1) { players.Add(playerList[i]); i = 0; } if (playerList[i].GetComponent <PlayerController>().playerType == PlayerController.PLAYER.PLAYER3 && players.Count == 2) { players.Add(playerList[i]); i = 0; } if (playerList[i].GetComponent <PlayerController>().playerType == PlayerController.PLAYER.PLAYER4 && players.Count == 3) { players.Add(playerList[i]); i = 99999; break; } } //Kill any players that have no controller bound DyanmicControllers.FindControllers(); Debug.Log("There are " + DyanmicControllers.controlNum + " Controllers"); for (int i = 1; i < players.Count + 1; i++) { if (i > DyanmicControllers.controlNum) { players[i - 1].GetComponent <PlayerController>().controllerNotBound = true; Debug.Log("Player: " + i + " which is " + players[i - 1].name + " is not allowed since our controller num is: " + DyanmicControllers.controlNum); } } StartCoroutine(checkPlayers()); }
void Update() { playercount = DyanmicControllers.FindControllers(); disabledCount = 4 - playercount; readycount = 0; for (int i = 0; i < playercount; i++) { CharacterSelection hold = GameObject.Find("players").transform.GetChild(i).GetComponent <CharacterSelection>(); if (hold.holdTimer >= hold.holdlengh) { readycount += 1; } } if (readycount == playercount) { countdown = true; } for (int i = 0; i < disabledCount; i++) { GameObject.Find("players").transform.GetChild(3 - i).GetComponent <Image>().color = new Color(0.0f, 0.0f, 0.0f, 0.5f); CharacterSelection charSelect1 = GameObject.Find("players").transform.GetChild(3 - i).GetComponent <CharacterSelection>(); charSelect1.holdTimer = charSelect1.holdlengh; } if (countdown == true) { for (int i = 0; i < playercount; i++) { CharacterSelection charSelect2 = GameObject.Find("players").transform.GetChild(3 - i).GetComponent <CharacterSelection>(); charSelect2.holdTimer = charSelect2.holdlengh; } countdowntimer += Time.deltaTime; if (countdowntimer >= fadetime) { for (int i = 0; i < playercount; i++) { characterSetter.playerSelections.Add(GameObject.Find("players").transform.GetChild(i).GetComponent <CharacterSelection>().currentSelection); } //SceneManager.LoadScene(2); FindObjectOfType <SceneSwitcher>().SceneSwitch("Game"); } } //fade //GameObject.Find("FADE").GetComponent<Image>().color = new Color(GameObject.Find("FADE").GetComponent<Image>().color.r, GameObject.Find("FADE").GetComponent<Image>().color.g, GameObject.Find("FADE").GetComponent<Image>().color.b, Mathf.Pow(Mathf.Sin((countdowntimer / fadetime) * (Mathf.PI / 2)), 2)); }