mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
CHANGED TO MIRROR
This commit is contained in:
@@ -3,27 +3,33 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
|
||||
// Erstellung von Teams
|
||||
// Auflistung von den Spielern
|
||||
// Verwaltung der Spieler und Teams
|
||||
//
|
||||
|
||||
public class GameMaster : MonoBehaviour
|
||||
{
|
||||
[Header("GameMaster")]
|
||||
[SerializeField] private List<Team> teams = new List<Team>();
|
||||
[SerializeField] private List<Player> Players = new List<Player>();
|
||||
private void Start()
|
||||
{
|
||||
|
||||
CreateTeam("Orange");
|
||||
CreateTeam("Blue");
|
||||
|
||||
MLAPI.NetworkManager.Singleton.StartHost();
|
||||
}
|
||||
|
||||
private void CreateTeam(string name, int score = 0)
|
||||
private void Update()
|
||||
{
|
||||
Team team = new Team(name, score);
|
||||
teams.Add(team);
|
||||
if (Input.GetKeyDown(KeyCode.H))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Confined;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.J))
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Team> GetTeams()
|
||||
{
|
||||
return teams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MLAPI;
|
||||
public class Networking : NetworkManager
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f54db2e39d506634a9373c6d52305187
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
[Header("PlayerMaster")]
|
||||
[SerializeField] private List<ServerPlayer> Players = new List<ServerPlayer>(); //Contains All Players which are currently connected/in-game
|
||||
//[SerializeField] private List<ServerPlayer> Players = new List<ServerPlayer>(); //Contains All Players which are currently connected/in-game
|
||||
|
||||
//JUST FOR DEBUG
|
||||
[SerializeField] private GameObject TestPlayer;
|
||||
@@ -21,7 +21,7 @@ public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
foreach(GameObject p in GameObject.FindGameObjectsWithTag("Player"))
|
||||
{
|
||||
Players.Add(new ServerPlayer(p));
|
||||
//Players.Add(new ServerPlayer(p));
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class PlayerMaster : MonoBehaviour
|
||||
//Join
|
||||
public void OnPlayerJoin(GameObject player) //When a Player joins
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
@@ -43,30 +43,30 @@ public class PlayerMaster : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
}
|
||||
Players.Add(new ServerPlayer(player));
|
||||
Players.Add(new ServerPlayer(player));*/
|
||||
}
|
||||
|
||||
//Leave
|
||||
public void OnPlayerLeave(GameObject player) //When a Player leaves
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
Players.Remove(p);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public int SyncHealth(GameObject player)
|
||||
{
|
||||
foreach (ServerPlayer p in Players)
|
||||
/*foreach (ServerPlayer p in Players)
|
||||
{
|
||||
if (p.Player == player)
|
||||
{
|
||||
return p.GetHealth();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ServerPlayer
|
||||
{
|
||||
public GameObject Player;
|
||||
public bool isAlive;
|
||||
public Team team;
|
||||
private int health;
|
||||
private int kills;
|
||||
private int deaths;
|
||||
private const int defaultHp = 100;
|
||||
|
||||
public ServerPlayer(GameObject _Player, bool _isAlive = true, int _health = defaultHp, int _kills = 0, int _deaths = 0, Team _team = null)
|
||||
{
|
||||
Player = _Player;
|
||||
isAlive = _isAlive;
|
||||
health = _health;
|
||||
kills = _kills;
|
||||
deaths = _deaths;
|
||||
team = _team;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2e457ad00c1a044a924a5bc00776df9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user