new: damage can now be dealt to units using DamageSources
This commit is contained in:
@@ -1,22 +1,36 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Drawing;
|
||||
using Reset;
|
||||
using Reset.Core;
|
||||
using Reset.Core.Tools;
|
||||
using Reset.Units;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.Serialization;
|
||||
using Unity.Netcode;
|
||||
|
||||
public class Player : NetworkBehaviour{
|
||||
public class Player : NetworkBehaviour, IKillable{
|
||||
[HideInInspector] public PlayerControls controls;
|
||||
[HideInInspector] public new PlayerCamera camera;
|
||||
|
||||
float IKillable.maxHealth{ get; set; }
|
||||
float IKillable.currentHealth{ get; set; }
|
||||
|
||||
void Awake(){
|
||||
GameManager.Player = gameObject;
|
||||
controls = GetComponent<PlayerControls>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
void Start(){
|
||||
if (((IKillable)this).maxHealth == 0f) {
|
||||
Debug.LogError($"Max health is not set for type of <b>{name}</b>. Setting to 100.");
|
||||
((IKillable)this).currentHealth = 100f;
|
||||
} else {
|
||||
((IKillable)this).currentHealth = ((IKillable)this).maxHealth;
|
||||
}
|
||||
|
||||
|
||||
if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) {
|
||||
Attach();
|
||||
} else {
|
||||
@@ -50,8 +64,29 @@ public class Player : NetworkBehaviour{
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
void Update(){
|
||||
using (Draw.WithColor(Color.blue)) {
|
||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2.2f, ((IKillable)this).currentHealth.ToString(),
|
||||
Color.blue);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(DamageSource[] sources){
|
||||
foreach (DamageSource source in sources) {
|
||||
TakeDamage(source);
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(DamageSource source){
|
||||
((IKillable)this).currentHealth -= source.damageDealt;
|
||||
|
||||
if (((IKillable)this).currentHealth <= 0) {
|
||||
Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Kill(){
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user