Skip to content

Instantly share code, notes, and snippets.

@soyliquid
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soyliquid/59ce4459481dab56f224 to your computer and use it in GitHub Desktop.
Save soyliquid/59ce4459481dab56f224 to your computer and use it in GitHub Desktop.
[Unity][Photon]自動でロビーにJoin→固定のルームにJoinする
using UnityEngine;
using System.Collections;
public class NetworkManager : Photon.MonoBehaviour {
public static NetworkManager Instance {
get { return _instance; }
}
private static NetworkManager _instance;
public GameObject Player;
void Awake(){
_instance = this;
DontDestroyOnLoad(this);
}
// Use this for initialization
void Start () {
JoinLobby();
}
void JoinLobby() {
Debug.Log(
"PhotonNetwork.sendRate=" + PhotonNetwork.sendRate + @"\r\n" +
"PhotonNetwork.sendRateOnSerialize=" + PhotonNetwork.sendRateOnSerialize
);
// 通信頻度を上げる
PhotonNetwork.sendRate = 30;
PhotonNetwork.sendRateOnSerialize = 30;
PhotonNetwork.ConnectUsingSettings("0.1");
}
void OnJoinedLobby() {
Debug.Log("OnJoinedLobby");
PhotonNetwork.JoinOrCreateRoom("DEFAULT", new RoomOptions(), TypedLobby.Default);
}
void OnJoinedRoom() {
Debug.Log("OnJoinedRoom");
PhotonNetwork.Instantiate(Player.name, Vector3.zero, Quaternion.identity, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment