mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
idk 2
This commit is contained in:
@@ -12,11 +12,19 @@ using UnityEngine;
|
||||
public class GameMaster : MonoBehaviour
|
||||
{
|
||||
[Header("GameMaster")]
|
||||
<<<<<<< Updated upstream
|
||||
[SerializeField] private List<Player> Players = new List<Player>();
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
=======
|
||||
[SerializeField] private List<Player> Players = new List<Player>();
|
||||
[SerializeField] private int countOfRounds = 10;
|
||||
|
||||
public GameObject localPlayer;
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -33,4 +41,13 @@ public class GameMaster : MonoBehaviour
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
|
||||
18
Assets/Scripts/GameManager/JoinLeaveManager.cs
Normal file
18
Assets/Scripts/GameManager/JoinLeaveManager.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
|
||||
public class JoinLeaveManager : MonoBehaviour
|
||||
{
|
||||
private NetworkManager networkManager;
|
||||
|
||||
public void Join(string ip, string username)
|
||||
{
|
||||
networkManager = GetComponent<NetworkManager>();
|
||||
|
||||
Debug.Log("[JoinLeaveManager] Trying to join server: " + ip + " as " + username);
|
||||
|
||||
networkManager.StartClient();
|
||||
networkManager.networkAddress = ip;
|
||||
Debug.Log("[JoinLeaveManager] " + username + " joined the server: " + ip);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GameManager/JoinLeaveManager.cs.meta
Normal file
11
Assets/Scripts/GameManager/JoinLeaveManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b62b46838717d934483010f517c5b772
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,14 +14,16 @@ public class Player : NetworkBehaviour
|
||||
|
||||
[SyncVar(hook = nameof(SetName))]
|
||||
public string username;
|
||||
|
||||
[SerializeField] GameObject usernameTextObj;
|
||||
|
||||
private int health;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
|
||||
public override void OnStartLocalPlayer()
|
||||
{
|
||||
base.OnStartClient();
|
||||
|
||||
//Load Player Username;
|
||||
|
||||
}
|
||||
|
||||
public void SetName(string oldName, string newName)
|
||||
@@ -29,100 +31,4 @@ public class Player : NetworkBehaviour
|
||||
username = newName;
|
||||
usernameTextObj.GetComponent<TMPro.TextMeshPro>().SetText(username);
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
public void Respawn()
|
||||
{
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
public void Die()
|
||||
{
|
||||
isAlive = false;
|
||||
AddDeaths(1);
|
||||
}
|
||||
|
||||
//Health
|
||||
public void AddHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health += value;
|
||||
}
|
||||
|
||||
}
|
||||
public void RemoveHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health -= value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void SetHealth(int value)
|
||||
{
|
||||
if (isAlive)
|
||||
{
|
||||
health = value;
|
||||
if (health <= 0)
|
||||
{
|
||||
AddDeaths(1);
|
||||
health = 0;
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
//Kills
|
||||
public void AddKills(int value)
|
||||
{
|
||||
kills += value;
|
||||
}
|
||||
public void RemoveKills(int value)
|
||||
{
|
||||
kills -= value;
|
||||
}
|
||||
public void SetKills(int value)
|
||||
{
|
||||
kills = value;
|
||||
}
|
||||
|
||||
public int GetKills()
|
||||
{
|
||||
return kills;
|
||||
}
|
||||
|
||||
//Deaths
|
||||
public void AddDeaths(int value)
|
||||
{
|
||||
deaths += value;
|
||||
}
|
||||
public void RemoveDeaths(int value)
|
||||
{
|
||||
deaths -= value;
|
||||
}
|
||||
public void SetDeaths(int value)
|
||||
{
|
||||
deaths = value;
|
||||
}
|
||||
|
||||
public int GetDeaths()
|
||||
{
|
||||
return deaths;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,26 @@ public class JoinBtnScript : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_InputField inputIp;
|
||||
[SerializeField] private TMP_InputField inputUsername;
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
private JoinLeaveManager joinLeaveManager;
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
private void Start()
|
||||
{
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(JoinServer);
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
joinLeaveManager = GameObject.Find("GameManager").GetComponent<JoinLeaveManager>();
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
|
||||
public void JoinServer()
|
||||
{
|
||||
<<<<<<< Updated upstream
|
||||
NetworkClient.Connect(inputIp.text);
|
||||
=======
|
||||
joinLeaveManager.Join(inputIp.text, inputUsername.text);
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user