Hey gang, I have a small problem with my game, everything seems to work find except with Client 1.
the first client to load stays on "Waiting for Players to Join" when the Second Client connects Client to Proceeds to show the "Launch" Button, Client 1 should also show the "LAUNCH" button when their are 2 or more Players in "Count of Players".
so plays can only start the game when both players are connected have I missed a step:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class ConnectOnline : Photon.MonoBehaviour {
public GameObject EarthMap;
public GameObject MarsMap;
public GameObject LaunchButton;
public float MapSelect;
public virtual void Start()
{
PhotonNetwork.autoJoinLobby = true; // we join randomly. always. no need to join a lobby to get the list of rooms.
PhotonNetwork.ConnectUsingSettings("0.1");
}
public 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 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();
RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 2 };
PhotonNetwork.JoinOrCreateRoom ("roomName", roomOptions, TypedLobby.Default);
}
public void OnPhotonRandomJoinFailed()
{
RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 2 };
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.JoinOrCreateRoom ("roomName", roomOptions, TypedLobby.Default);
}
public void Update() {
if(PhotonNetwork.countOfPlayers == 2){
LaunchButton.SetActive (true);
}
if (PhotonNetwork.isMasterClient == true && PhotonNetwork.countOfPlayers == 2) {
MapSelect = 0;
MapSelect = Random.Range (0, 6);
if (MapSelect > 0 && MapSelect < 3.1) {
EarthMap.SetActive (true);
photonView.RPC ("FireOtherTeam1", PhotonTargets.OthersBuffered);
}
if (MapSelect > 3.1 && MapSelect < 6) {
MarsMap.SetActive (true);
photonView.RPC ("FireOtherTeam2", PhotonTargets.OthersBuffered);
}
}
}
[PunRPC]
void FireOtherTeam2 (){
EarthMap.SetActive (true);
}
[PunRPC]
void FireOtherTeam1 (){
MarsMap.SetActive (true);
}
}
![![alt text][1]][1]
[1]: /storage/temp/106246-screen-shot-2017-11-26-at-51607-pm.png
↧