- Home /
Multiple cameras in multiplayer
I'm having the same kind of problem as the one mentioned here: http://answers.unity3d.com/questions/1405957/cameras-in-multiplayer-game-unity.html
So basically, I'm trying to make a multiplayer game, and I've set-up the networking using unity. In the network controller, I've set the player prefab to be the FPS Controller with a network identity. However, when I try to have two instances of the game running (the host and the client), when the client connects to the host, the host's camera is switched to the same camera as the client. How do I set it up so that the host and client have different views or cameras? Any help is much appreciated.
Thanks!
EDIT - Forgot to mention that I'm fairly new to Unity and if this is a noob question, sorry in advance.
Answer by ristophonics · Jan 19, 2018 at 07:22 AM
Okay, I had the same problem and followed the posts until I could create the following answer. On the playerprefab being instantiated I placed the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CameraControllerNet : NetworkBehaviour {
private GameObject cameraRigToGrab;
public GameObject _cameraPositionMarker; //an empty on my player where the cam should be
public override void OnStartLocalPlayer()
{
cameraRigToGrab = GameObject.Find("OVRCameraRigForCG"); //actually camera's parent
if (isLocalPlayer)
{
cameraRigToGrab.transform.position = _cameraPositionMarker.transform.position;
cameraRigToGrab.transform.rotation = _cameraPositionMarker.transform.rotation;
cameraRigToGrab.transform.SetParent(_cameraPositionMarker.transform);
return;
}
}
}
First: You DO NOT unintentionally want more then one Camera in the scene, so simply remove any from prefabs that might generate them automatically and place your ONE MainCamera in the scene alone. My MainCamera in the script below is "OVRCameraRigCG." Just replace that name with your MainCamera's parent name. If your MainCamera does not have a parent create an EmptyGameobject as it parent, name it MainCameraRig and reference that name exactly.
The script essentially says: 1) Find the camera in the scene that I want. 2) Move that camera to the position and rotation of my CameraMarker // this is an empty Gameobject on the playerprefab where you want you camera to be 3) Make the CameraMarker my camera's new parent
Hope that helps. It tests out working so far.
Your answer
Follow this Question
Related Questions
SplitScreen shooter with Viewmodels and PlayerModels without so many layers? 1 Answer
Unity networking tutorial? 6 Answers
How to Modify Multiplayer Script for iPhone 0 Answers
How do i turn on and off a network camera? 0 Answers
Webplayer Facebook game- is a PHP script and a Unity script sufficient? 0 Answers