I am coding for a game that has single and multiplayer. When I host a multiplayer server and use another window of the build to act as a client, the host controls both the server and client player prefabs. Below is the input controller that moves the players;
void OnConnectedToServer()
{
if(!networkView.isMine)
{enabled = false;}
}
void Start ()
{
//If in multiplayer, make sure only the right net player has control
if((Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server))
{
if(networkView.isMine)
{
SetUpPlayerCamera();
enabled = true;
}
else
{
enabled = false;
}
}
//Otherwise if in SP, give control
else
{
SetUpPlayerCamera();
}
}
void OnNetworkInstantiate(NetworkMessageInfo msg)
{
if(!networkView.isMine)
{enabled = false;}
}
void Update ()
{
//If in multiplayer, make sure the right player controls this
if((Network.peerType == NetworkPeerType.Client || Network.peerType == NetworkPeerType.Server))
{
if(networkView.isMine)
{ InputControl();}
}
else
{
InputControl();
}
}
I used the networkView.isMine method which is in every other answer but for me the scripts are always enabled for the host and not the client, or any client for that matter. When I play as a client in the editor, I see input of both players disabled.
What am I doing wrong? Help would be appreciated.