new: damage can now be dealt to units using DamageSources

This commit is contained in:
Chris
2025-10-03 20:44:48 -04:00
parent 06cfd582c8
commit 7068d39b5b
11 changed files with 188 additions and 16 deletions

View File

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