- Home /
Problems with respawn and camera disable after instantiation ..? Help please
i have a problem
Im trying to create a respawn in my unity c sharp/photon project. I can die, then it goes back to my object camera “standbyCamera” view, which is my default main menu view. After 3 seconds it is suppose to respawn me, but it doesn’t, can someone please help me!
I’ve been following quill18creates multiplayer fps tutorial, you can download the project files here: http://quill18.com/unity_tutorials/MultiFPS/
keep in mind i had to change some things because of his version not matching up with mine. Anything referring to the Camera, cam, or standby Camera is where my problem is.
If you have any ideas on what i could do or where i should start on trouble shooting this and finding where it fails?
i know for a fact that my standbyCamera is suppose to disabled after ‘3f’ or 3 seconds has happened, but in my inspector it stays on
HEALTH
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Health : MonoBehaviour { public float hitPoints =100f; float currentHitPoints; #pragma warning disable 618 // Use this for initialization void Start () { currentHitPoints = hitPoints; } [PunRPC] public void TakeDamage (float amt) { currentHitPoints -= amt; if (currentHitPoints <= 0) { Die (); } } void OnGUI() { if (GetComponent ().isMine && gameObject.tag == "Player") { if (GUI.Button (new Rect (Screen.width - 100, 0, 100, 40), "Suicide!")) { Die (); } } } void Die(){ if(GetComponent().instantiationId == 0){ Destroy(gameObject); } else { if (GetComponent ().isMine) { if(gameObject.tag == "player") { //This is my actual PLAYER object, then initiate the respawn proces NetworkManager nm = GameObject.FindObjectOfType (); //nm.GetComponentInChildren().enabled = true; nm.standbyCamera.SetActive(true); nm.respawnTimer = 3f; } PhotonNetwork.Destroy (gameObject); } } } }
NETWORK MANAGER
using System.Collections; using System.Collections.Generic; using UnityEngine; public class NetworkManager : MonoBehaviour{ public Camera standbyCamera; SpawnSpots[] SpawnSpots; public bool offlineMode = false; bool connecting = false; IList chatMessages; int maxChatMessages = 10; public float respawnTimer = 0; // Use this for initialization void Start () { SpawnSpots = GameObject.FindObjectsOfType (); PhotonNetwork.player.NickName = PlayerPrefs.GetString ("Username", "New Player"); chatMessages = new List (); } void OnDestroy () { PlayerPrefs.SetString ("Username", PhotonNetwork.player.NickName); } public void AddChatMessage (string m) { GetComponent ().RPC ("AddChatMessage_PunRPC", PhotonTargets.AllBuffered, m); } [PunRPC] public void AddChatMessage_PunRPC (string m) { while (chatMessages.Count >= maxChatMessages) { chatMessages.RemoveAt (0); } chatMessages.Add (m); } void Connect (){ PhotonNetwork.ConnectUsingSettings ("Multi v0.0.1"); } void OnGUI () { GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString() ); if(PhotonNetwork.connected == false && connecting == false ) { GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height) ); GUILayout.BeginHorizontal (); GUILayout.FlexibleSpace (); GUILayout.BeginVertical (); GUILayout.FlexibleSpace (); GUILayout.BeginHorizontal (); GUILayout.Label ("Username: "); PhotonNetwork.player.NickName = GUILayout.TextField(PhotonNetwork.player.NickName); GUILayout.EndHorizontal (); if (GUILayout.Button ("Single Player")) { connecting = true; PhotonNetwork.offlineMode = true; OnConnectedToMaster (); } if (GUILayout.Button ("Multiplayer")) { connecting = true; Connect (); } GUILayout.FlexibleSpace (); GUILayout.EndVertical (); GUILayout.FlexibleSpace (); GUILayout.EndHorizontal (); GUILayout.EndArea (); } if (PhotonNetwork.connected == true && connecting == false) { GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height) ); GUILayout.BeginVertical (); GUILayout.FlexibleSpace (); foreach (string msg in chatMessages){ GUILayout.Label (msg); } GUILayout.EndVertical (); GUILayout.EndArea (); } } void OnConnectedToMaster() { Debug.Log ("OnJoinedLobby"); PhotonNetwork.JoinRandomRoom (); PhotonNetwork.JoinLobby (); } void OnPhotonRandomJoinFailed(){ Debug.Log ("OnPhotonRandomJoinFailed"); PhotonNetwork.CreateRoom (null); } void OnJoinedRoom() { Debug.Log ("OnJoinedRoom"); connecting = false; SpawnMyPlayer(); } void SpawnMyPlayer() { AddChatMessage ("Spawning player: " + PhotonNetwork.player.NickName); if (SpawnSpots == null) { Debug.LogError ("WTF?!?!?"); return; } SpawnSpots mySpawnSpot = SpawnSpots [Random.Range (0, SpawnSpots.Length)]; GameObject myPlayerGO = (GameObject) PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0); ((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true; myPlayerGO.GetComponent().enabled = true; myPlayerGO.GetComponent().enabled = true; myPlayerGO.GetComponentInChildren().enabled = true; myPlayerGO.GetComponent().enabled = true; //myPlayerGO.GetComponentInChildren ().enabled = true; //myPlayerGO.GetComponentInChildren().enabled = true; } void Update() { if(respawnTimer > 0) { respawnTimer -= Time.deltaTime; if (respawnTimer <= 0) { //Time to respawn the player! } } } }
If you need any information or anything of me that can help you help me, please shoot! im very stuck!
Your answer
Follow this Question
Related Questions
How to get your player to respawn when in void (C#) 2 Answers
Respawn Time 1 Answer
How to implement a respawn/lives system in Space Shooter (the tutorial game)? 0 Answers
respawn player problems 5 Answers