Okay this is really weird and basically i use 2 computers and on one computer i use both the pc build and the unity engine and as far as i can tell 2 players have an id of 3 2 of which are on different systems and also 2 players lost control of their character. The camera is inside the character prefab.
here is the code
here is the code
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
/// <summary>
/// This script automatically connects to Photon (using the settings file),
/// tries to join a random room and creates one if none was found (which is ok).
/// </summary>
public class ConnectAndJoinRandom : Photon.MonoBehaviour
{
/// <summary>Connect automatically? If false you can set this to true later on or call ConnectUsingSettings in your own scripts.</summary>
public bool AutoConnect = true;
public GameObject player;
[SerializeField]
private GameObject[] spawnPoints;
public byte Version = 1;
/// <summary>if we don't want to connect in Start(), we have to "remember" if we called ConnectUsingSettings()</summary>
private bool ConnectInUpdate = true;
public virtual void Start()
{
PhotonNetwork.autoJoinLobby = true; // we join randomly. always. no need to join a lobby to get the list of rooms.
}
public virtual void Update()
{
if (ConnectInUpdate && AutoConnect && !PhotonNetwork.connected)
{
Debug.Log("Update() was called by Unity. Scene is loaded. Let's connect to the Photon Master Server. Calling: PhotonNetwork.ConnectUsingSettings();");
ConnectInUpdate = true;
PhotonNetwork.ConnectUsingSettings(Version + "0.1" + SceneManagerHelper.ActiveSceneBuildIndex);
}
}
// below, we implement some callbacks of PUN
// you can find PUN's callbacks in the class PunBehaviour or in enum PhotonNetworkingMessage
public virtual void OnConnectedToMaster()
{
Debug.Log("OnConnectedToMaster() was called by PUN. Now this client is connected and could join a room. Calling: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
}
public virtual void OnJoinedLobby()
{
Debug.Log("OnJoinedLobby(). This client is connected and does get a room-list, which gets stored as PhotonNetwork.GetRoomList(). This script now calls: PhotonNetwork.JoinRandomRoom();");
PhotonNetwork.JoinRandomRoom();
}
public virtual void OnPhotonRandomJoinFailed()
{
Debug.Log("OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one. Calling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);");
PhotonNetwork.CreateRoom(null, new RoomOptions() { MaxPlayers = 4 }, null);
}
// the following methods are implemented to give you some context. re-implement them as needed.
public virtual void OnFailedToConnectToPhoton(DisconnectCause cause)
{
Debug.LogError("Cause: " + cause);
}
public void OnJoinedRoom()
{
PhotonNetwork.Instantiate (player.transform.name, Vector3.zero, Quaternion.identity, 0);
Debug.Log("OnJoinedRoom() called by PUN. Now this client is in a room. From here on, your game would be running. For reference, all callbacks are listed in enum: PhotonNetworkingMessage");
}
}