mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
added PlayerClass with Sync
This commit is contained in:
@@ -329,6 +329,7 @@ GameObject:
|
|||||||
- component: {fileID: 340159600}
|
- component: {fileID: 340159600}
|
||||||
- component: {fileID: 340159599}
|
- component: {fileID: 340159599}
|
||||||
- component: {fileID: 340159598}
|
- component: {fileID: 340159598}
|
||||||
|
- component: {fileID: 340159601}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Player
|
m_Name: Player
|
||||||
m_TagString: Player
|
m_TagString: Player
|
||||||
@@ -396,6 +397,20 @@ Transform:
|
|||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 3
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
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
|
||||||
--- !u!1 &450235891 stripped
|
--- !u!1 &450235891 stripped
|
||||||
GameObject:
|
GameObject:
|
||||||
m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
|
||||||
@@ -1093,6 +1108,8 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
Players: []
|
Players: []
|
||||||
Health:
|
Health:
|
||||||
|
Kills:
|
||||||
|
Deaths:
|
||||||
defaultHp: 100
|
defaultHp: 100
|
||||||
TestPlayer: {fileID: 1187582346}
|
TestPlayer: {fileID: 1187582346}
|
||||||
--- !u!1 &1111479331 stripped
|
--- !u!1 &1111479331 stripped
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ DEAD
|
|||||||
*/
|
*/
|
||||||
public class PlayerMaster : MonoBehaviour
|
public class PlayerMaster : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[Header("PlayerMaster")]
|
||||||
[SerializeField] private List<GameObject> Players = new List<GameObject>(); //Contains All Players which are currently connected/in-game
|
[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 List<int> Health = new List<int>();
|
||||||
[SerializeField] private List<int> Kills = new List<int>();
|
[SerializeField] private List<int> Kills = new List<int>();
|
||||||
|
|||||||
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.GetHealthOfPlayer(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
|
//Jump
|
||||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||||
{
|
{
|
||||||
Debug.Log("Jump");
|
//Debug.Log("Jump");
|
||||||
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user