Just recently started using UNET and it has been difficult, to say the least.
I'm trying execute a few lines of code to essentially have the server assign a spawned prefab (aka the Player) a camera, set it's position and parent it to said prefab. This works fine as soon as the server is hosted - camera is attached, follows the player.. great!
However, as soon as a client joins, I get an "Object reference not set to an instance of an object" error.
Client
void RpcSetCamera()
{
if (go.gameObject == null)
{
Debug.Log("Unable to attach camera");
return;
}
Camera.main.transform.position = go.transform.position - go.transform.forward * 8 + go.transform.up * 2;
Camera.main.transform.LookAt(go.transform);
Camera.main.transform.parent = go.transform;
}
Here's the function that is called for the client.