mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
added PlayerClass with Sync
This commit is contained in:
@@ -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>();
|
||||
|
||||
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
|
||||
if (Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
Debug.Log("Jump");
|
||||
//Debug.Log("Jump");
|
||||
velocityY += Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user