Advertisement
Guest User

Manager / Menu

a guest
Sep 17th, 2019
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class Menu : MonoBehaviour
  5. {
  6.     int state = 0;
  7.     public GameObject[] menuWindows; //0 = Loading Panel | 1 = Login | 2 = Ingame
  8.  
  9.     public InputField usernameInput;
  10.  
  11.  
  12.     void Start() {
  13.         SwitchState(0);
  14.         ConnectToPhoton();
  15.     }
  16.  
  17.     void Update(){
  18.        
  19.     }
  20.  
  21.     void OnGUI() {
  22.         GUI.Label(new Rect(10, 10, 300, 50), PhotonNetwork.connectionStateDetailed.ToString());
  23.     }
  24.  
  25.     void ConnectToPhoton() {
  26.         PhotonNetwork.ConnectUsingSettings("V1");
  27.     }
  28.  
  29.     void OnJoinedLobby() {
  30.         PhotonNetwork.JoinRandomRoom();
  31.     }
  32.  
  33.     void OnPhotonRandomJoinFailed() {
  34.         PhotonNetwork.CreateRoom("The Beast");
  35.     }
  36.  
  37.     void OnJoinedRoom() {
  38.         SwitchState(1);
  39.     }
  40.  
  41.     public void LoginSubmit() {
  42.         if (usernameInput.text.Length > 4) {
  43.             PhotonNetwork.player.NickName = usernameInput.text;
  44.             SpawnCharacter();
  45.         } else {
  46.             Debug.Log("Longer Name Please!");
  47.         }
  48.     }
  49.  
  50.     void SpawnCharacter() {
  51.         GameObject myChar = (GameObject)PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
  52.         myChar.GetComponent<PlayerInput>().enabled = true;
  53.         GameObject.Find("Tracker").GetComponent<Tracker>().target = myChar.transform;
  54.         SwitchState(2);
  55.     }
  56.  
  57.  
  58.  
  59.     void SwitchState(int nextState) {
  60.         for (int i = 0; i <  menuWindows.Length; i++) {
  61.             menuWindows[i].SetActive(false);
  62.         }
  63.  
  64.         if (menuWindows[nextState] != null) {
  65.             menuWindows[nextState].SetActive(true);
  66.         }
  67.  
  68.     }
  69.  
  70.     public void ActivateFun() { //Start Button
  71.         SwitchState(1);
  72.     }
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement