// Start is called before the first frame update void Start() { anim = GetComponent <Animator>(); if (hasAuthority == true) { this.gameObject.name = "LocalPlayer"; } else { this.gameObject.name = "RemotePlayer"; } lives = 3; Respawning = false; GameObject server = GameObject.FindGameObjectWithTag("Server"); //System.Random rnd = new System.Random(System.Guid.NewGuid().GetHashCode()); //int randomType = rnd.Next(0, 3); //switch(randomType) //{ // case 0: // elementType = ElementEnum.Elements.Fire; // break; // case 1: // elementType = ElementEnum.Elements.Water; // break; // case 2: // elementType = ElementEnum.Elements.Grass; // break; //} serverRef = server.GetComponent <Server>(); //initialize the render renderer1 = gameObject.GetComponent <Renderer>(); if (isServer == true) { RpcSetType(elementType); } else { CmdSetType(elementType); } //freeze rotation gameObject.GetComponent <Rigidbody>().freezeRotation = true; tempLives = new LivesStruct(this.gameObject.GetComponent <NetworkIdentity>().netId.ToString(), 3, this.gameObject); serverRef.playerLives.Add(tempLives); }
public void RpcPlayerRespawn() { /// Debug.Log("RPCPLAYERRESPAWN BEING CALLED"); if (duplicateCheck == false) { CheckForDuplicates(); } for (int i = 0; i < playerLives.Count; i++) { Debug.Log("Net ID: " + playerLives[i].netID + " Players lives left " + playerLives[i].lives); } //Debug.Log("A player won"); bool foundPlayer = false; int foundIndex = -1; for (int i = 0; i < playerLives.Count; i++) { //Debug.Log("Struct net id: " + playerLives[i].netID + " Player Net ID" + myPlayer.GetComponent<NetworkIdentity>().netId.ToString() + "Struct net id Currentlives : " + playerLives[i].lives); if (playerLives[i].netID == myPlayer.GetComponent <NetworkIdentity>().netId.ToString()) { foundPlayer = true; foundIndex = i; i = playerLives.Count + 1; } } if (foundIndex != -1) { Debug.Log("We are chaging " + playerLives[foundIndex].netID + "from " + playerLives[foundIndex].lives + " lives to -1 of that"); LivesStruct temp = playerLives[foundIndex]; temp.lives = temp.lives - 1; playerLives[foundIndex] = temp; if (playerLives[foundIndex].lives > 0) { StartCoroutine(PlayerRespawnWait()); } //Debug.Log("Results of Check winstate:" + CheckWinState()); } CheckWinState(); }