mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Add HealthSystem and Base Structure of DeadSystem
HEALTH - Set Health of a player - Subtract Health from a player - Add Health to a player DEAD - Player Dies - Another Player gets a kill
This commit is contained in:
@@ -38,7 +38,7 @@ RenderSettings:
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 705507994}
|
||||
m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
|
||||
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
@@ -714,6 +714,55 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||
--- !u!1 &808644082
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 808644085}
|
||||
- component: {fileID: 808644084}
|
||||
m_Layer: 0
|
||||
m_Name: Player4
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!143 &808644084
|
||||
CharacterController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 808644082}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Height: 2
|
||||
m_Radius: 0.5
|
||||
m_SlopeLimit: 45
|
||||
m_StepOffset: 0.1
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
--- !u!4 &808644085
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 808644082}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 4.57, y: 2.15, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &857589336
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -931,6 +980,55 @@ Transform:
|
||||
m_Father: {fileID: 340159600}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: -84.997, z: 0}
|
||||
--- !u!1 &992344781
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 992344784}
|
||||
- component: {fileID: 992344783}
|
||||
m_Layer: 0
|
||||
m_Name: Player2
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!143 &992344783
|
||||
CharacterController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 992344781}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Height: 2
|
||||
m_Radius: 0.5
|
||||
m_SlopeLimit: 45
|
||||
m_StepOffset: 0.1
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
--- !u!4 &992344784
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 992344781}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -6.27, y: 2.15, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1035340512 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: -208595431880416365, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||
@@ -995,6 +1093,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
Players: []
|
||||
Health:
|
||||
defaultHp: 100
|
||||
TestPlayer: {fileID: 1187582346}
|
||||
--- !u!1 &1111479331 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 2550463727306718371, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||
@@ -1014,6 +1114,55 @@ MeshCollider:
|
||||
m_Convex: 0
|
||||
m_CookingOptions: 30
|
||||
m_Mesh: {fileID: -629719859055844128, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||
--- !u!1 &1187582346
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1187582349}
|
||||
- component: {fileID: 1187582348}
|
||||
m_Layer: 0
|
||||
m_Name: Player3
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!143 &1187582348
|
||||
CharacterController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1187582346}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Height: 2
|
||||
m_Radius: 0.5
|
||||
m_SlopeLimit: 45
|
||||
m_StepOffset: 0.1
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 1, z: 0}
|
||||
--- !u!4 &1187582349
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1187582346}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -11.01, y: 2.15, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 8
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1246681035
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -5,20 +5,51 @@ 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.
|
||||
3. Player bekommt einen Eintrag in die Health-Liste (Der Schl<68>ssel ist hier, dass der Index bei beiden Listen f<>r den gleichen Spieler stehen)
|
||||
|
||||
LEAVE
|
||||
1. Index von dem Spieler, in der Liste, wird gesucht
|
||||
2. Spieler wird aus der Liste entfernt
|
||||
3. Player wird aus der Health liste ausgetragen
|
||||
|
||||
|
||||
HEALTH
|
||||
- Set Health of a player
|
||||
- Subtract Health from a player
|
||||
- Add Health to a player
|
||||
|
||||
DEAD
|
||||
- Player Dies
|
||||
- Another Player gets a kill
|
||||
|
||||
*/
|
||||
public class PlayerMaster : MonoBehaviour
|
||||
{
|
||||
[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>();
|
||||
[SerializeField] private int defaultHp = 100;
|
||||
|
||||
//JUST FOR DEBUG
|
||||
[SerializeField] private GameObject TestPlayer;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//JUST FOR DEBUG
|
||||
/*Debug.Log(GetHealthOfPlayer(TestPlayer));
|
||||
SubstractHealthFromPlayer(TestPlayer, 1);*/
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Players.AddRange(GameObject.FindGameObjectsWithTag("Player")); //Add All Player-GameObjects into a List
|
||||
|
||||
//Init Health List
|
||||
foreach(GameObject player in Players)
|
||||
{
|
||||
Health.Add(defaultHp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Join
|
||||
@@ -28,6 +59,7 @@ public class PlayerMaster : MonoBehaviour
|
||||
if (!Players.Contains(player)) //If the Player is NOT in the "Players-List" (For Error Handling)
|
||||
{
|
||||
Players.Add(player); //Add New Player To List
|
||||
Health.Add(defaultHp); //Add New Health to the END of the list
|
||||
Debug.Log("Player added to list"); //Feedback
|
||||
}
|
||||
else
|
||||
@@ -43,10 +75,52 @@ public class PlayerMaster : MonoBehaviour
|
||||
if (Players.Contains(player))//If the Player IS in the "Players-List" (For Error Handling)
|
||||
{
|
||||
Players.Remove(player); //Remove the Player from List
|
||||
Health.Remove(Players.IndexOf(player)); //Remove the specific Health of the Player
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Player not found in Players-list"); //Error, because the Player is NOT in the list -> !critical Anomaly!
|
||||
}
|
||||
}
|
||||
|
||||
//Health
|
||||
private void CheckIfPlayerAlive(GameObject player)//Is a Player dead?
|
||||
{
|
||||
if (GetHealthOfPlayer(player) <= 0)
|
||||
{
|
||||
Death(player);
|
||||
}
|
||||
}
|
||||
public int GetHealthOfPlayer(GameObject player) //Get The Health value of a player
|
||||
{
|
||||
return Health[Players.IndexOf(player)];
|
||||
}
|
||||
public void SetHealthOfPlayer(GameObject player, int value) //z.B. wenn ein spieler getroffen wird und dmg bekommt
|
||||
{
|
||||
Health[Players.IndexOf(player)] = value;
|
||||
CheckIfPlayerAlive(player);
|
||||
}
|
||||
|
||||
public void SubstractHealthFromPlayer(GameObject player, int value) //z.B. wenn ein spieler getroffen wird und dmg bekommt
|
||||
{
|
||||
Health[Players.IndexOf(player)] -= value;
|
||||
CheckIfPlayerAlive(player);
|
||||
}
|
||||
|
||||
public void AddHealthToPlayer(GameObject player, int value) //z.B. wenn ein spieler geheilt wird
|
||||
{
|
||||
Health[Players.IndexOf(player)] += value;
|
||||
}
|
||||
|
||||
//Death
|
||||
public void Death(GameObject deadPlayer, GameObject killerPlayer = null) //Player dies and and MAYBE another player gets a kill
|
||||
{
|
||||
if(killerPlayer != null)
|
||||
{
|
||||
//Add kill to killer
|
||||
}
|
||||
|
||||
//Add Death to deadPlayer
|
||||
//Deactivate deadPlayer
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user