Hello, I am in the process of trying to convert my camera system from single player to multiplayer. It works great if I connect one user to the server, but once I add in anymore users, the camera seems to attach itself to the first user’s version of the game object. Individual movements are controlling their respected characters and they still rotate and move around properly, just the camera is always attached to the first user connected.
This code is from my TP_Camera script.
public static void UseExistingOrCreateNewMainCamera()
{
GameObject tempCamera;
GameObject targetLookAt;
TP_Camera myCamera;
if(Camera.mainCamera != null)
{
tempCamera = Camera.mainCamera.gameObject;
}
else
{
tempCamera = new GameObject("Main Camera");
tempCamera.AddComponent ("Camera");
tempCamera.tag = "MainCamera";
}
tempCamera.AddComponent("TP_Camera");
myCamera = tempCamera.GetComponent ("TP_Camera") as TP_Camera;
targetLookAt = GameObject.Find("targetLookAt") as GameObject;
myCamera.TargetLookAt = targetLookAt.transform;
}
Here is where it is called from the TP_Controller script.
void Awake()
{
if(networkView.isMine == true)
{
CharacterController = GetComponent ("CharacterController") as CharacterController;
Instance = this;
TP_Camera.UseExistingOrCreateNewMainCamera();
}
else
enabled = false;
I am fairly certain that it is occurring because every instance is looking for the first game object “targetLookAt” rather than the child of its instance, but everything I’ve tried either leads to more problems or just doesn’t work.
I did get the network camera to follow the proper instances when I created a simple new camera and had it attach to a transform through transform.FindChild() instead of a game object, but trying to do that within the UseExistingOrCreateNewMainCamera function didn’t attach the camera to anything at all.
The myCamera.TargetLookAt = transformHereInsteadOfGameObject; line either didn’t attach itself to the transform or transformHereInsteadOfGameObject = transform.FindChild(“targetLookAt”); didn’t work.
Any tips on the best way to solve this? Thank you.