mirror of
				https://github.com/DerTyp7/defrain-shooter-unity.git
				synced 2025-10-29 20:52:10 +01:00 
			
		
		
		
	Merge branch 'player-master' into game-master
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: | ||||
| @@ -329,9 +329,10 @@ GameObject: | ||||
|   - component: {fileID: 340159600} | ||||
|   - component: {fileID: 340159599} | ||||
|   - component: {fileID: 340159598} | ||||
|   - component: {fileID: 340159601} | ||||
|   m_Layer: 0 | ||||
|   m_Name: Player | ||||
|   m_TagString: Untagged | ||||
|   m_TagString: Player | ||||
|   m_Icon: {fileID: 0} | ||||
|   m_NavMeshLayer: 0 | ||||
|   m_StaticEditorFlags: 0 | ||||
| @@ -396,6 +397,21 @@ Transform: | ||||
|   m_Father: {fileID: 0} | ||||
|   m_RootOrder: 3 | ||||
|   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||||
| --- !u!114 &340159601 | ||||
| MonoBehaviour: | ||||
|   m_ObjectHideFlags: 0 | ||||
|   m_CorrespondingSourceObject: {fileID: 0} | ||||
|   m_PrefabInstance: {fileID: 0} | ||||
|   m_PrefabAsset: {fileID: 0} | ||||
|   m_GameObject: {fileID: 340159597} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 3317f24e780855847830f5662153b41d, type: 3} | ||||
|   m_Name:  | ||||
|   m_EditorClassIdentifier:  | ||||
|   health: 100 | ||||
|   SyncIntervalSeconds: 5 | ||||
|   GameManager: {fileID: 1067101116} | ||||
| --- !u!1 &450235891 stripped | ||||
| GameObject: | ||||
|   m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} | ||||
| @@ -714,6 +730,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 +996,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} | ||||
| @@ -990,10 +1104,15 @@ MonoBehaviour: | ||||
|   m_GameObject: {fileID: 1067101116} | ||||
|   m_Enabled: 1 | ||||
|   m_EditorHideFlags: 0 | ||||
|   m_Script: {fileID: 11500000, guid: 26ee7b094ee25bf49aaf5ffba35f8cf6, type: 3} | ||||
|   m_Script: {fileID: 11500000, guid: cb5ee5f3d2923ee4faeaf50ed35ab2f5, type: 3} | ||||
|   m_Name:  | ||||
|   m_EditorClassIdentifier:  | ||||
|   scores:  | ||||
|   Players: [] | ||||
|   Health:  | ||||
|   Kills:  | ||||
|   Deaths:  | ||||
|   defaultHp: 100 | ||||
|   TestPlayer: {fileID: 1187582346} | ||||
| --- !u!1 &1111479331 stripped | ||||
| GameObject: | ||||
|   m_CorrespondingSourceObject: {fileID: 2550463727306718371, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} | ||||
| @@ -1013,6 +1132,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 | ||||
|   | ||||
							
								
								
									
										72
									
								
								Assets/Scripts/GameManager/PlayerMaster.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								Assets/Scripts/GameManager/PlayerMaster.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| 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 | ||||
|  | ||||
|     //JUST FOR DEBUG | ||||
|     [SerializeField] private GameObject TestPlayer; | ||||
|  | ||||
|     private void Update() | ||||
|     { | ||||
|         //JUST FOR DEBUG | ||||
|         Players[0].AddKills(1); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         foreach(GameObject p in GameObject.FindGameObjectsWithTag("Player")) | ||||
|         { | ||||
|             Players.Add(new ServerPlayer(p)); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         InvokeRepeating("TestDamage", 3.0f, 3f); | ||||
|     } | ||||
|  | ||||
|     public void TestDamage() | ||||
|     { | ||||
|         Players[0].RemoveHealth(10); | ||||
|     } | ||||
|     //Join | ||||
|     public void OnPlayerJoin(GameObject player) //When a Player joins | ||||
|     { | ||||
|         foreach (ServerPlayer p in Players) | ||||
|         { | ||||
|             if (p.Player == player) | ||||
|             { | ||||
|                 Debug.Log("Joined Player already exits"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
|         Players.Add(new ServerPlayer(player)); | ||||
|     } | ||||
|  | ||||
|     //Leave | ||||
|     public void OnPlayerLeave(GameObject player) //When a Player leaves | ||||
|     { | ||||
|         foreach (ServerPlayer p in Players) | ||||
|         { | ||||
|             if (p.Player == player) | ||||
|             { | ||||
|                 Players.Remove(p); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public int SyncHealth(GameObject player) | ||||
|     { | ||||
|         foreach (ServerPlayer p in Players) | ||||
|         { | ||||
|             if (p.Player == player) | ||||
|             { | ||||
|                 return p.GetHealth(); | ||||
|             } | ||||
|         } | ||||
|         return -1; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/GameManager/PlayerMaster.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/GameManager/PlayerMaster.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: cb5ee5f3d2923ee4faeaf50ed35ab2f5 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										114
									
								
								Assets/Scripts/GameManager/ServerPlayer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								Assets/Scripts/GameManager/ServerPlayer.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class ServerPlayer | ||||
| { | ||||
|     public GameObject Player; | ||||
|     public bool isAlive; | ||||
|     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) | ||||
|     { | ||||
|         Player = _Player; | ||||
|         isAlive = _isAlive; | ||||
|         health = _health; | ||||
|         kills = _kills; | ||||
|         deaths = _deaths; | ||||
|     } | ||||
|  | ||||
|     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; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/GameManager/ServerPlayer.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/GameManager/ServerPlayer.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: c2e457ad00c1a044a924a5bc00776df9 | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
							
								
								
									
										35
									
								
								Assets/Scripts/Player/Player.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Assets/Scripts/Player/Player.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
|  | ||||
| public class Player : MonoBehaviour | ||||
| { | ||||
|     [SerializeField] int health; | ||||
|     [SerializeField] float SyncIntervalSeconds = 5.0f; | ||||
|     [SerializeField] GameObject GameManager; | ||||
|  | ||||
|     private PlayerMaster playerMaster; | ||||
|  | ||||
|     private void Start() | ||||
|     { | ||||
|         playerMaster = GameManager.GetComponent<PlayerMaster>(); | ||||
|         InvokeRepeating("Sync", 3.0f, SyncIntervalSeconds); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     private void Sync() | ||||
|     { | ||||
|         Debug.Log("Sync"); | ||||
|         health = playerMaster.SyncHealth(gameObject); | ||||
|     } | ||||
|  | ||||
|     public void SubstractHealth(int value) | ||||
|     { | ||||
|         health -= value; | ||||
|     } | ||||
|  | ||||
|     public void AddHealth(int value) | ||||
|     { | ||||
|         health += value; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/Player/Player.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Player/Player.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 3317f24e780855847830f5662153b41d | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @@ -80,7 +80,7 @@ public class PlayerController : MonoBehaviour | ||||
|         //Jump | ||||
|         if (Input.GetButtonDown("Jump") && isGrounded) | ||||
|         { | ||||
|             Debug.Log("Jump"); | ||||
|             //Debug.Log("Jump"); | ||||
|             velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity); | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 DerTyp187
					DerTyp187