void Awake() { #region Create Player Objects //Create Player player1Inst = (GameObject)Instantiate(playerPrefab, player1SpawnCoords, Quaternion.identity); player2Inst = (GameObject)Instantiate(playerPrefab, player2SpawnCoords, new Quaternion(45, 180, 0, 1)); //Create Game Manager gameManager = (GameObject)Instantiate(gameManagerPrefab, new Vector3(0,0,0), Quaternion.identity); gmScript = gameManager.GetComponent<script_2PGameManager>(); player1Inst.gameObject.name = "Player 1"; player2Inst.gameObject.name = "Player 2"; EnablePlayer1(); int randSelect = Random.Range(0,2); { if (randSelect == 0) { //Assign Player 1 to Nerd Debug.Log("Player should be a Nerd."); playerScript.playerType = script_2PPlayer.PlayerType.Nerd; //Assign Player 2 to Jock playerScript = player2Inst.GetComponent<script_2PPlayer>(); playerScript.playerType = script_2PPlayer.PlayerType.Jock; playerScript.enabled = false; //Give Player 1 his script back playerScript = player1Inst.GetComponent<script_2PPlayer>(); } else if (randSelect == 1) { //Assign Player 1 to Jock Debug.Log("Player should be a Jock."); playerScript.playerType = script_2PPlayer.PlayerType.Jock; //Assign Player 2 to Nerd playerScript = player2Inst.GetComponent<script_2PPlayer>(); playerScript.playerType = script_2PPlayer.PlayerType.Nerd; playerScript.enabled = false; //Give Player 1 his script back playerScript = player1Inst.GetComponent<script_2PPlayer>(); } } #endregion }
//This method is used in the turn system to turn on and off all //of the components that the player will need now that it is his turn //First disables all of the other player's components public void EnablePlayer1() { #region Disable Player 2 if (gmScript.turnNumber > 1) { childCam = player2Inst.transform.FindChild("Camera").gameObject; playerCam = childCam.gameObject.GetComponent<Camera>(); unitCam = player2Inst.transform.FindChild("UnitCam").gameObject.GetComponent<Camera>(); playerAudio = player2Inst.gameObject.GetComponent<AudioListener>(); playerScript = player2Inst.gameObject.GetComponent<script_2PPlayer>(); cam = player2Inst.gameObject.GetComponent<RtsCamera>(); camKeys = player2Inst.gameObject.GetComponent<RtsCameraKeys>(); camMouse = player2Inst.gameObject.GetComponent<RtsCameraMouse>(); effectsUpdater = player2Inst.gameObject.GetComponent<RtsEffectsUpdater>(); targetScript = player2Inst.gameObject.GetComponent<TargetMover>(); playerView = player2Inst.gameObject.GetComponent<Camera>(); playerScript.isMyTurn = false; camKeys.enabled = false; camMouse.enabled = false; cam.enabled = false; effectsUpdater.enabled = false; targetScript.enabled = false; playerCam.enabled = false; unitCam.enabled = false; playerAudio.enabled = false; playerView.enabled = false; playerScript.enabled = false; } #endregion #region Enabled Player 1 if (mainCam != null) { mainCam = Camera.main; GameObject.Destroy(mainCam.gameObject); } childCam = player1Inst.transform.FindChild("Camera").gameObject; playerCam = childCam.gameObject.GetComponent<Camera>(); unitCam = player1Inst.transform.FindChild("UnitCam").gameObject.GetComponent<Camera>(); camKeys = player1Inst.gameObject.GetComponent<RtsCameraKeys>(); camMouse = player1Inst.gameObject.GetComponent<RtsCameraMouse>(); cam = player1Inst.gameObject.GetComponent<RtsCamera>(); playerScript = player1Inst.gameObject.GetComponent<script_2PPlayer>(); effectsUpdater = player1Inst.gameObject.GetComponent<RtsEffectsUpdater>(); targetScript = player1Inst.gameObject.GetComponent<TargetMover>(); playerAudio = player1Inst.gameObject.GetComponent<AudioListener>(); playerView = player1Inst.gameObject.GetComponent<Camera>(); playerAudio.enabled = true; camKeys.enabled = true; camMouse.enabled = true; cam.enabled = true; playerScript.enabled = true; effectsUpdater.enabled = true; targetScript.enabled = true; playerView.enabled = true; if (gmScript.turnNumber <= 2) { cam.MinBounds = playerMinCoords; cam.MaxBounds = playerMaxCoords; cam.LookAt = player1SpawnCoords; } playerCam.enabled = true; unitCam.enabled = true; playerScript.isMyTurn = true; playerScript.movesRemaining = 5; #endregion }
void Start() { turnNumber = 1; setupScript = GameObject.Find("prefab_2PSetup").GetComponent<script_2PSetup>(); player1 = GameObject.Find("Player 1"); player1Script = player1.GetComponent<script_2PPlayer>(); player2 = GameObject.Find("Player 2"); player2Script = player2.GetComponent<script_2PPlayer>(); AssignPlayers(); if (turnNumber == 1) { Debug.Log("Setting Player 1's Turn"); player1Script.movesRemaining = 5; player2Turn = false; setupScript.EnablePlayer1(); player1Script.isMyTurn = true; player1Turn = true; StartCoroutine("Player1Banner"); if (player1Type == Player1Type.Jock) { AkSoundEngine.PostEvent("Set_Team_Jocks", gameObject); } else { AkSoundEngine.PostEvent("Set_Team_Nerds", gameObject); } NewTurnSound(); } if(turnNumber%2==0) { //Even Turn Debug.Log("Setting Player 2's Turn."); turnName = TurnName.player2Turn; player1Turn = false; player1Script.isMyTurn = false; setupScript.EnablePlayer2(); player2Script.isMyTurn = true; player2Script.movesRemaining = 5; player2Turn = true; StartCoroutine("Player2Banner"); if (player2Type == Player2Type.Jock) { AkSoundEngine.PostEvent("Set_Team_Jocks", gameObject); } else { AkSoundEngine.PostEvent("Set_Team_Nerds", gameObject); } } else if (turnNumber%2==1) { //Odd Turn Debug.Log("Setting Player 1's Turn."); turnName = TurnName.player1Turn; player2Script.isMyTurn = false; player2Turn = false; setupScript.EnablePlayer1(); player1Turn = true; player1Script.isMyTurn = true; player1Script.movesRemaining = 5; StartCoroutine("Player1Banner"); if (player1Type == Player1Type.Jock) { AkSoundEngine.PostEvent("Set_Team_Jocks", gameObject); } else { AkSoundEngine.PostEvent("Set_Team_Nerds", gameObject); } } PlayMusic(); }