public void selectCaracter(int num) { if (isPressed) { return; } isPressed = true; for (int i = 0; i < buttons.Length; i++) { if (i == num) { GameObject newChar = Instantiate(characters[num], player[i].transform.position, player[i].transform.rotation); player[i].gameObject.transform.SetParent(newChar.transform); player[i].transform.localPosition = offsetPosition; player[i].activeteCanvs(); newChar.transform.SetParent(gamescene.transform); Inputhandler hand = newChar.GetComponent <Inputhandler>(); hand.InitInGame(); } else { GameObject newChar = Instantiate(cpuCharacters[i], player[i].transform.position, player[i].transform.rotation); player[i].transform.SetParent(newChar.transform); player[i].transform.localPosition = offsetPosition; newChar.transform.SetParent(gamescene.transform); Camerahandler hand = player[i].GetComponentInChildren <Camerahandler>(); Destroy(hand.gameObject); CPUBrain brain = newChar.GetComponent <CPUBrain>(); brain.INIT(player[i]); } buttons[i].SetActive(false); } B_GameManager.instance.StartcountDown(true); }
public void SpawnCharacters() { if (isPressed) { return; } isPressed = true; for (int i = 0; i < characters.Length; i++) { if (i < (int)maxPlayers) { player[i].playerID = "P" + (i + 1) + "_"; GameObject newChar = Instantiate(characters[i], player[i].transform.position, player[i].transform.rotation); player[i].gameObject.transform.SetParent(newChar.transform); player[i].transform.localPosition = offsetPosition; player[i].activeteCanvs(); player[i].GetComponentInChildren <Camera>().targetDisplay = i; newChar.transform.SetParent(gamescene.transform); Inputhandler hand = newChar.GetComponent <Inputhandler>(); hand.InitInGame(); } else { GameObject newChar = Instantiate(cpuCharacters[i], player[i].transform.position, player[i].transform.rotation); player[i].transform.SetParent(newChar.transform); player[i].transform.localPosition = offsetPosition; newChar.transform.SetParent(gamescene.transform); Camerahandler hand = player[i].GetComponentInChildren <Camerahandler>(); Destroy(hand.gameObject); CPUBrain brain = newChar.GetComponent <CPUBrain>(); brain.INIT(player[i]); } } B_GameManager.instance.StartcountDown(true); }