This commit is contained in:
DerTyp187
2021-10-28 08:29:41 +02:00
parent 57ee0da640
commit f2e8de1537
13 changed files with 362 additions and 144 deletions

View File

@@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
// Erstellung von Teams
@@ -12,10 +12,10 @@ using UnityEngine;
public class GameMaster : MonoBehaviour
{
[Header("GameMaster")]
[SerializeField] private List<Player> Players = new List<Player>();
[SerializeField] private List<Player> Players = new List<Player>();
public GameObject localPlayer;
private void Start()
{
}
private void Update()
@@ -33,4 +33,8 @@ public class GameMaster : MonoBehaviour
Cursor.visible = false;
}
}
}

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Manager : NetworkManager
{
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
//Debug.Log(conn.identity.gameObject.GetComponent<Player>().username);
//conn.identity.gameObject.GetComponent<Player>().username = "Test";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58bd0a0557e21bf4e8ea0e0cd4e9d057
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveData : MonoBehaviour
{
[SerializeField] PlayerData _PlayerData = new PlayerData();
private void Start()
{
gameObject.GetComponent<Button>().onClick.AddListener(SavePlayerToJson);
}
public void SavePlayerToJson()
{
string playerData = JsonUtility.ToJson(_PlayerData);
System.IO.File.WriteAllText(Application.persistentDataPath + "/PlayerData.json", playerData);
Debug.Log(Application.persistentDataPath);
}
}
[System.Serializable]
public class PlayerData
{
public string username;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 039d8e4cae766214180c87269a6218db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,13 +4,15 @@ using UnityEngine;
public class HostBtnScript : MonoBehaviour
{
private GameObject GameManager;
private void Start()
{
gameObject.GetComponent<Button>().onClick.AddListener(HostServer);
GameManager = GameObject.Find("GameManager");
}
public void HostServer()
{
NetworkClient.ConnectHost();
GameManager.GetComponent<NetworkManager>().StartHost();
}
}

View File

@@ -7,14 +7,22 @@ public class JoinBtnScript : MonoBehaviour
{
[SerializeField] private TMP_InputField inputIp;
[SerializeField] private TMP_InputField inputUsername;
private GameObject GameManager;
private NetworkManager networkManager;
public GameObject localPlayer;
private void Start()
{
gameObject.GetComponent<Button>().onClick.AddListener(JoinServer);
GameManager = GameObject.Find("GameManager");
networkManager = GameManager.GetComponent<NetworkManager>();
}
public void JoinServer()
{
NetworkClient.Connect(inputIp.text);
networkManager.StartClient();
networkManager.networkAddress = inputIp.text;
}
}