Question by
SlyGameStudios · Sep 21, 2016 at 04:43 PM ·
c#cameranetworking
Multiplayer Cameras
ok so I'm trying to get 2 players to spawn in and have there own cameras and are controlled separately by the clients. I got 2 players to spawn in but there is only one camera they are both controlled by the host. please help
using UnityEngine;
using System.Collections;
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;
}
// Use this for initialization
void Start ()
{
if (isLocalPlayer)
GetComponent<FirstPersonCharacter>().enabled = true;
}
void Update()
{
this.GetComponentInChildren<TextMesh>().text = pname;
}
}
![alt text][1]
Comment