// Use this for initialization void Start() { Leader.enabled = false; currentPlayer = Player1; direccion = Vector3.left; CamDir = direccion; phase = 0; playerChanger = false; Player1.GetComponent <ExplosionBallScript> ().StartTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = false; Player2.GetComponent <AllBallsNeedThis> ().isWating = true; Player3.GetComponent <AllBallsNeedThis> ().isWating = true; }
private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { mind.changePlayer(Player1); Player1.GetComponent <PlayerController>().enabled = true; Player1.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; } if (Input.GetKeyDown(KeyCode.Alpha2)) { mind.changePlayer(Player2); Player2.GetComponent <PlayerController>().enabled = true; Player2.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; } if (Input.GetKeyDown(KeyCode.Alpha3)) { mind.changePlayer(Player3); Player3.GetComponent <PlayerController>().enabled = true; Player3.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; } }
IEnumerator changePlayer() { playerChanger = true; yield return(new WaitForSeconds(1f)); while (currentPlayer.GetComponent <Rigidbody> ().velocity != Vector3.zero) { yield return(null); } if (currentPlayer == Player1) { if (!Player2.GetComponent <AllBallsNeedThis> ().done) { currentPlayer = Player2; Player2.GetComponent <BlinkBallScript> ().StartTurn(); Player1.GetComponent <ExplosionBallScript> ().notMyTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = true; Player2.GetComponent <AllBallsNeedThis> ().isWating = false; Player3.GetComponent <AllBallsNeedThis> ().isWating = true; } else if (!Player3.GetComponent <AllBallsNeedThis>().done) { currentPlayer = Player3; Player3.GetComponent <GravityBallScript> ().StartTurn(); Player1.GetComponent <ExplosionBallScript> ().notMyTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = true; Player2.GetComponent <AllBallsNeedThis> ().isWating = true; Player3.GetComponent <AllBallsNeedThis> ().isWating = false; } } else if (currentPlayer == Player2) { if (!Player3.GetComponent <AllBallsNeedThis> ().done) { currentPlayer = Player3; Player3.GetComponent <GravityBallScript> ().StartTurn(); Player1.GetComponent <ExplosionBallScript> ().notMyTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = true; Player2.GetComponent <AllBallsNeedThis> ().isWating = true; Player3.GetComponent <AllBallsNeedThis> ().isWating = false; } else if (!Player1.GetComponent <AllBallsNeedThis>().done) { currentPlayer = Player1; Player1.GetComponent <ExplosionBallScript> ().StartTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = false; Player2.GetComponent <AllBallsNeedThis> ().isWating = true; Player3.GetComponent <AllBallsNeedThis> ().isWating = true; } } else if (currentPlayer == Player3) { if (!Player1.GetComponent <AllBallsNeedThis> ().done) { currentPlayer = Player1; Player1.GetComponent <ExplosionBallScript> ().StartTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = false; Player2.GetComponent <AllBallsNeedThis> ().isWating = true; Player3.GetComponent <AllBallsNeedThis> ().isWating = true; } else if (!Player2.GetComponent <AllBallsNeedThis>().done) { currentPlayer = Player2; Player2.GetComponent <BlinkBallScript> ().StartTurn(); Player1.GetComponent <ExplosionBallScript> ().notMyTurn(); Player1.GetComponent <AllBallsNeedThis> ().isWating = true; Player2.GetComponent <AllBallsNeedThis> ().isWating = false; Player3.GetComponent <AllBallsNeedThis> ().isWating = true; } } phase = 0; playerChanger = false; }
void Start() { Nick[0] = PlayerPrefs.GetString("Player1"); Nick[1] = PlayerPrefs.GetString("Player2"); Nick[2] = PlayerPrefs.GetString("Player3"); Nick[3] = PlayerPrefs.GetString("Player4"); PlCount = PlayerPrefs.GetInt("PlayerCounter"); switch (PlCount) { case 2: CamOptions[0].SetActive(true); CamOptions[1].SetActive(false); CamOptions[2].SetActive(false); Player1 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro1")], PlSpawn[0].position, Quaternion.identity); Player1.name = "Player1"; Player1.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[0]; Player1.GetComponent <CarController>().PlID = 1; Player2 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro2")], PlSpawn[1].position, Quaternion.identity); Player2.name = "Player2"; Player2.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[1]; Player2.GetComponent <CarController>().PlID = 2; break; case 3: CamOptions[0].SetActive(false); CamOptions[1].SetActive(true); CamOptions[2].SetActive(false); Player1 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro1")], PlSpawn[0].position, Quaternion.identity); Player1.name = "Player1"; Player1.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[0]; Player1.GetComponent <CarController>().PlID = 1; Player2 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro2")], PlSpawn[1].position, Quaternion.identity); Player2.name = "Player2"; Player2.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[1]; Player2.GetComponent <CarController>().PlID = 2; Player3 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro3")], PlSpawn[2].position, Quaternion.identity); Player3.name = "Player3"; Player3.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[2]; Player3.GetComponent <CarController>().PlID = 3; break; case 4: CamOptions[0].SetActive(false); CamOptions[1].SetActive(false); CamOptions[2].SetActive(true); Player1 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro1")], PlSpawn[0].position, Quaternion.identity); Player1.name = "Player1"; Player1.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[0]; Player1.GetComponent <CarController>().PlID = 1; Player2 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro2")], PlSpawn[1].position, Quaternion.identity); Player2.name = "Player2"; Player2.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[1]; Player2.GetComponent <CarController>().PlID = 2; Player3 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro3")], PlSpawn[2].position, Quaternion.identity); Player3.name = "Player3"; Player3.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[2]; Player3.GetComponent <CarController>().PlID = 3; Player4 = Instantiate(PlCar[PlayerPrefs.GetInt("Carro4")], PlSpawn[3].position, Quaternion.identity); Player4.name = "Player4"; Player4.transform.FindChild("Nick").GetComponent <TextMesh>().text = Nick[3]; Player4.GetComponent <CarController>().PlID = 4; break; } }