Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ModelArt · Apr 07, 2017 at 03:03 PM · camerarespawnrespawning

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!

 }
 
 }
 }

}



Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ModelArt · Apr 07, 2017 at 10:08 AM 0
Share

If you need any information or anything of me that can help you help me, please shoot! im very stuck!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to get your player to respawn when in void (C#) 2 Answers

Can you guys Help me create a spawn mechanism where the player actually respawns in a platform(check for more details) 0 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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges