- Home /
Multiplayer camera switch issue
Hello I'm trying to create multiplayer game where I have Player prefab which is simply model of a airplane and camera attached to it as a child. When I start the server (server is a 1. player at the same time) it works prefectly, but when 2. or any other player joins the game their cameras switch positions (camera of the 1. player follows 2. player and and 2. camera follows 1. player). I've googled some posts about this, but none of them quite helped me solve this problem.
When i make only my model as prefab without the camera, then I look trough the main camera and movement and joining works fine for all players. But I suppose it's because everybody is looking trough the same camera.
Well the guess is that something goes wrong when I'm creating cameras from that prefab, but I have no Idea what could be wrong.
This is my spawn script:
public class SpawnScript : MonoBehaviour {
public Transform player;
void OnServerInitialized(){
Spawn();
}
void OnConnectedToServer(){
Spawn();
}
void Spawn(){
Network.Instantiate(player, transform.position, Quaternion.identity, 0);
}
}
}
This is playerControl script:
public class PlayerControl : MonoBehaviour {
public float speed = 5;
void Start () {
if(!networkView.isMine){
enabled = false;
}
}
void Update () {
if(networkView.isMine){
Vector3 moveDir = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
transform.Translate(speed * moveDir * Time.deltaTime);
}
}
}
I'm fairly new to Unity and scripting in C# so any help would be appreciated. Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613140647im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Simple Camera look script (MULTIPLAYER) 0 Answers
Trying to follow tutorial to set up Multiplayer camera follow on UNET... and it goes wrong. 0 Answers
How to trigger camera capture on each player in Unity Networking? 0 Answers
One camera in multiplayer? 2 Answers