Hi,
I was trying to code a simple multiplayer for my game. I got stuck when setting the correct camera for a joined player. When the client player joins my host player the cameras get switched. Camera A for player A is now snapped to player B and vice versa. Here is my code for the player after the prefab:
Code
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class PlayerSetup : NetworkBehaviour {
int counter;
Camera sceneCamera;
private GUIStyle winStyle = new GUIStyle();
public Camera cameraUp;
public Camera cameraDown;
void Start ()
{
if (!isLocalPlayer)
{
this.GetComponent<SimpleCarController>().enabled = false;
return;
}
else
{
Camera.main.enabled = false;
cameraUp.enabled = true;
Debug.Log("Camera switch");
winStyle.fontSize = 80;
winStyle.alignment = TextAnchor.UpperCenter;
winStyle.normal.textColor = Color.white;
RegisterPlayer();
OnGUI();
}
}
void RegisterPlayer()
{
string _ID = "Player " + GetComponent<NetworkIdentity>().netId;
cameraUp.name = "camUp" + _ID;
cameraDown.name = "camDown" + _ID;
transform.name = _ID;
Debug.Log("Register was here");
}
void FixUpdate()
{
OnGUI();
}
public void OnGUI()
{
counter = count.currentCounthub;
GUI.Label(new Rect(20f, 20f, 100f, 30f), "Count: " + counter.ToString());
//win-lose
if (counter == 3)
{
GUI.Label(new Rect(Screen.width / 2, Screen.height / 2, 0f, 30f), "You Win!", winStyle);
}
}
}
Can you please help me to figure out what went wrong?