mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Added Documentation for Join/Leave List
This commit is contained in:
@@ -4,48 +4,49 @@ using UnityEngine;
|
||||
/*
|
||||
JOIN
|
||||
1. Wenn ein Spieler joined wird sichergestellt, dass er nicht in der Liste ist (f<>rs error handling).
|
||||
2. Dann wird er in die Liste "Players" eingetragen und ein Eintrag in der "health" liste wird mit dem selben index gemacht.
|
||||
2. Dann wird er in die Liste "Players" eingetragen.
|
||||
|
||||
LEAVE
|
||||
1. Index von dem Spieler, in der Liste, wird gesucht
|
||||
2. Spieler wird aus der Liste entfernt
|
||||
3. health index vom spieler wird auch entfernt
|
||||
|
||||
*/
|
||||
public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<GameObject> Players = new List<GameObject>();
|
||||
[SerializeField] private List<GameObject> Players = new List<GameObject>(); //Contains All Players which are currently connected/in-game
|
||||
[SerializeField] private List<int> Health = new List<int>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Players.AddRange(GameObject.FindGameObjectsWithTag("Player"));
|
||||
Players.AddRange(GameObject.FindGameObjectsWithTag("Player")); //Add All Player-GameObjects into a List
|
||||
}
|
||||
|
||||
public void OnPlayerJoin(GameObject player)
|
||||
//Join
|
||||
public void OnPlayerJoin(GameObject player) //When a Player joins
|
||||
{
|
||||
Debug.Log("Player joined");
|
||||
if (!Players.Contains(player))
|
||||
Debug.Log("Player joined"); //Give Console Feedback
|
||||
if (!Players.Contains(player)) //If the Player is NOT in the "Players-List" (For Error Handling)
|
||||
{
|
||||
Players.Add(player);
|
||||
Debug.Log("Player added to list");
|
||||
Players.Add(player); //Add New Player To List
|
||||
Debug.Log("Player added to list"); //Feedback
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Player already exits in list");
|
||||
Debug.LogError("Player already exits in list"); //Error, because the "new" Player is already in the list -> !critical Anomaly!
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerLeave(GameObject player)
|
||||
//Leave
|
||||
public void OnPlayerLeave(GameObject player) //When a Player leaves
|
||||
{
|
||||
Debug.Log("Player left");
|
||||
if (Players.Contains(player))
|
||||
Debug.Log("Player left");//Give Console Feedback
|
||||
if (Players.Contains(player))//If the Player IS in the "Players-List" (For Error Handling)
|
||||
{
|
||||
Players.Remove(player);
|
||||
Players.Remove(player); //Remove the Player from List
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Player not found in Players-list");
|
||||
Debug.LogError("Player not found in Players-list"); //Error, because the Player is NOT in the list -> !critical Anomaly!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user