Created
January 16, 2018 10:39
-
-
Save hurr1star/c265a42d78d36199aa7081b1a82350c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class NetworkManager : MonoBehaviour { | |
GameObject mainMenu; | |
// Methode um Serverbindung aufzubauen | |
public void Connect() | |
{ | |
Debug.Log ("Connect wird ausgeführt"); | |
// Befehl für die Verbindung zum Photon Network | |
PhotonNetwork.ConnectUsingSettings("v01"); | |
} | |
void OnConnectedToMaster() | |
{ | |
Debug.Log ("Mit Master verbunden. Szene für Lobby laden"); | |
PhotonNetwork.JoinLobby (); | |
} | |
void OnJoinedLobby() | |
{ | |
Debug.Log ("Wir sind mit der Lobby verbunden."); | |
mainMenu.SetActive (false); | |
// Zufälligen Raum betreten | |
PhotonNetwork.JoinRandomRoom(); | |
} | |
void OnPhotonRandomJoinFailed() | |
{ | |
PhotonNetwork.CreateRoom(null); | |
} | |
void OnJoinedRoom() | |
{ | |
// Spawn ausführen | |
Spawn(); | |
} | |
void Spawn() | |
{ | |
//int randomX = Random.Range (-8, +8); | |
//int randomY = Random.Range (-4, +4); | |
// Erscheinen des Prefabs | |
PhotonNetwork.Instantiate ("Player", new Vector3(0, 0, 0), Quaternion.identity, 0); | |
} | |
// Use this for initialization | |
void Start () { | |
mainMenu = GameObject.Find ("MainMenu"); | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
// Ausgabe des aktuellen Serverstatus | |
Debug.Log(PhotonNetwork.connectionStateDetailed.ToString()); | |
// Ausgabe Anzahl weiterer Spieler im Raum | |
Debug.Log("Anzahl weiterer Spieler: " + PhotonNetwork.otherPlayers.Length); | |
} | |
public void SaveNickName() | |
{ | |
string nickName = GameObject.Find ("NickNameText").GetComponent<Text> ().text.ToString (); | |
// Nicknamen in der Szene finden und zwischenspeichern | |
print(nickName); | |
// Gespeicherten Nicknamen an Photon übergeben | |
PhotonNetwork.player.NickName = nickName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment