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

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