Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class Menu : MonoBehaviour
- {
- int state = 0;
- public GameObject[] menuWindows; //0 = Loading Panel | 1 = Login | 2 = Ingame
- public InputField usernameInput;
- void Start() {
- SwitchState(0);
- ConnectToPhoton();
- }
- void Update(){
- }
- void OnGUI() {
- GUI.Label(new Rect(10, 10, 300, 50), PhotonNetwork.connectionStateDetailed.ToString());
- }
- void ConnectToPhoton() {
- PhotonNetwork.ConnectUsingSettings("V1");
- }
- void OnJoinedLobby() {
- PhotonNetwork.JoinRandomRoom();
- }
- void OnPhotonRandomJoinFailed() {
- PhotonNetwork.CreateRoom("The Beast");
- }
- void OnJoinedRoom() {
- SwitchState(1);
- }
- public void LoginSubmit() {
- if (usernameInput.text.Length > 4) {
- PhotonNetwork.player.NickName = usernameInput.text;
- SpawnCharacter();
- } else {
- Debug.Log("Longer Name Please!");
- }
- }
- void SpawnCharacter() {
- GameObject myChar = (GameObject)PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
- myChar.GetComponent<PlayerInput>().enabled = true;
- GameObject.Find("Tracker").GetComponent<Tracker>().target = myChar.transform;
- SwitchState(2);
- }
- void SwitchState(int nextState) {
- for (int i = 0; i < menuWindows.Length; i++) {
- menuWindows[i].SetActive(false);
- }
- if (menuWindows[nextState] != null) {
- menuWindows[nextState].SetActive(true);
- }
- }
- public void ActivateFun() { //Start Button
- SwitchState(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement