private void Start() { gm = FindObjectOfType <vGameController>(); }
/// <summary> /// Will set the death message based on the inputs and broadcasts that message via the /// Chatbox's data channel to everyone in the session, but only if you allow this. Enables /// the respawn visual component and starts the countdown. After waiting for the `respawnDelay` /// time it calls `NetworkInstantiatePrefab` from the NetworkManager to instantiate your /// new player and sets all of its needed values at a target respawn point. It will then /// destroy the old player based on the photonView. /// </summary> /// <param name="playerView">PhotonView type, the photonview of the player respawning</param> /// <param name="keepItems">bool type, keep the items of the player that is respawning</param> /// <param name="lastDamager">Gameobject type, the gameobject of the thing that dealt the last bit of damage</param> /// <param name="lastDamageType">string type, the type of damage that was received.</param> protected virtual IEnumerator RespawnAction(PhotonView playerView, bool keepItems, GameObject lastDamager = null, string lastDamageType = "") { GameObject respawnVisual = null; if (broadcastDeathMessage == true) { deathMessage = deathMessage.Replace("{Nickname}", playerView.Owner.NickName); if (string.IsNullOrEmpty(lastDamageType)) { deathMessage = deathMessage.Replace("{DamageType}", "a unknown damage type"); } else { deathMessage = deathMessage.Replace("{DamageType}", lastDamageType); } if (lastDamager != null) { if (lastDamager.tag == "Player") { deathMessage = deathMessage.Replace("{Damager}", "themself"); } else if (lastDamager.GetComponent <PhotonView>() || lastDamager.transform.GetComponentInParent <PhotonView>()) { string playerName; if (lastDamager.GetComponent <PhotonView>()) { playerName = lastDamager.GetComponent <PhotonView>().Owner.NickName; } else { playerName = lastDamager.transform.GetComponentInParent <PhotonView>().Owner.NickName; } deathMessage = deathMessage.Replace("{Damager}", playerName); } else { deathMessage = deathMessage.Replace("{Damager}", lastDamager.name.Replace("(Clone)", "")); } } else { deathMessage = deathMessage.Replace("{Damager}", "a unknown damager"); } BroadCastMessage message = new BroadCastMessage( "DEATH", deathMessage ); NetworkManager.networkManager.GetChabox().BroadcastData( NetworkManager.networkManager.GetChatDataChannel(), message ); } if (visualCountdown != null) { respawnVisual = Instantiate(visualCountdown) as GameObject; respawnVisual.SendMessage("StartCounting", respawnDelay); } respawnPoint = SelectRespawnPoint(playerView); yield return(new WaitForSeconds(respawnDelay)); if (respawnVisual != null) { Destroy(respawnVisual); } PhotonNetwork.Destroy(playerView); if (!playerView.GetComponentInChildren <vInventory>() && FindObjectOfType <vInventory>()) { Destroy(FindObjectOfType <vInventory>().gameObject); } yield return(new WaitForEndOfFrame()); GameObject newPlayer = NetworkManager.networkManager.NetworkInstantiatePrefab( NetworkManager.networkManager.playerPrefab.name, respawnPoint.position, respawnPoint.rotation, 0 ); FindObjectOfType <vThirdPersonCamera>().target = (newPlayer.GetComponentInChildren <vLookTarget>()) ? newPlayer.GetComponentInChildren <vLookTarget>().transform : newPlayer.transform; newPlayer.GetComponent <vThirdPersonController>().isDead = false; if (FindObjectOfType <vGameController>()) { vGameController gc = FindObjectOfType <vGameController>(); if (gc != null) { gc.currentPlayer = newPlayer; } } yield return(new WaitForFixedUpdate()); if (keepItems == true) { NetworkManager.networkManager.LoadPlayerData( playerView.Owner.NickName, newPlayer.GetComponent <vThirdPersonController>(), false, true, true ); } }
void Start() { gm = GetComponent <vGameController>(); }
void Start() { gm = GetComponentInParent <vGameController>(); this.GetComponent <BoxCollider>().isTrigger = true; }