53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using Photon;
|
|
using UnityEngine;
|
|
|
|
public class RandomMatchmaker : PunBehaviour
|
|
{
|
|
private PhotonView myPhotonView;
|
|
|
|
public void Start()
|
|
{
|
|
PhotonNetwork.ConnectUsingSettings("0.1");
|
|
}
|
|
|
|
public override void OnJoinedLobby()
|
|
{
|
|
Debug.Log("JoinRandom");
|
|
PhotonNetwork.JoinRandomRoom();
|
|
}
|
|
|
|
public override void OnConnectedToMaster()
|
|
{
|
|
PhotonNetwork.JoinRandomRoom();
|
|
}
|
|
|
|
public void OnPhotonRandomJoinFailed()
|
|
{
|
|
PhotonNetwork.CreateRoom(null);
|
|
}
|
|
|
|
public override void OnJoinedRoom()
|
|
{
|
|
GameObject gameObject = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
|
|
gameObject.GetComponent<myThirdPersonController>().isControllable = true;
|
|
myPhotonView = gameObject.GetComponent<PhotonView>();
|
|
}
|
|
|
|
public void OnGUI()
|
|
{
|
|
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
|
|
if (PhotonNetwork.inRoom)
|
|
{
|
|
bool flag = GameLogic.playerWhoIsIt == PhotonNetwork.player.ID;
|
|
if (flag && GUILayout.Button("Marco!"))
|
|
{
|
|
myPhotonView.RPC("Marco", PhotonTargets.All);
|
|
}
|
|
if (!flag && GUILayout.Button("Polo!"))
|
|
{
|
|
myPhotonView.RPC("Polo", PhotonTargets.All);
|
|
}
|
|
}
|
|
}
|
|
}
|