Question by
SlyGameStudios · Sep 22, 2016 at 10:59 PM ·
c#cameranetworkingmultiplayerfps
Networking Fps Cameras
ok so when i start the game it works fien but when a client joins the server it deletes the host camera and plays through the newest camera but the host still has control over his original player prefab. I have Camera and First Person Controller turned off inside unity
using UnityEngine;
using UnityEngine.Networking;
public class SetupLocalPlayer : NetworkBehaviour {
[SyncVar]
public string pname = "player";
void OnGUI()
{
if(isLocalPlayer)
{
pname = GUI.TextField (new Rect (25, Screen.height - 40, 100, 30), pname);
if (GUI.Button (new Rect (130, Screen.height - 40, 80, 30), "Change"))
{
CmdChangeName (pname);
}
}
}
[Command]
public void CmdChangeName(string newName)
{
pname = newName;
this.GetComponentInChildren<TextMesh>().text = pname;
}
// Use this for initialization
void Start ()
{
if(isLocalPlayer)
GetComponent<FirstPersonCharacter>().enabled = true;
GetComponent<Camera>().enabled = true;
}
void Update()
{
this.GetComponentInChildren<TextMesh>().text = pname;
}
}
Comment
ok i got it from that to now both players are controlled by whatever window I'm using, doesn't matter host or client. please help
do i need to add a 2nd camera? i thought that it would create a 2nd camera when the 2nd player spawned