added PlayerClass with Sync

This commit is contained in:
DerTyp187
2021-10-14 20:16:38 +02:00
parent e057a569a5
commit 666e4f479f
5 changed files with 65 additions and 1 deletions

View File

@@ -329,6 +329,7 @@ GameObject:
- component: {fileID: 340159600}
- component: {fileID: 340159599}
- component: {fileID: 340159598}
- component: {fileID: 340159601}
m_Layer: 0
m_Name: Player
m_TagString: Player
@@ -396,6 +397,20 @@ 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
--- !u!1 &450235891 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
@@ -1093,6 +1108,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
Players: []
Health:
Kills:
Deaths:
defaultHp: 100
TestPlayer: {fileID: 1187582346}
--- !u!1 &1111479331 stripped

View File

@@ -25,6 +25,7 @@ DEAD
*/
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<int> Health = new List<int>();
[SerializeField] private List<int> Kills = new List<int>();

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3317f24e780855847830f5662153b41d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);
}