aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs
diff options
context:
space:
mode:
authorSmallFox <2806143047@qq.com>2026-05-10 11:16:18 +0800
committerSmallFox <2806143047@qq.com>2026-05-10 11:16:18 +0800
commita9cef4bb0b902e3ec2d3b5510e3de4e885f2be90 (patch)
tree05bcb55df0ffc5be1f4d02c2cba6c5ad831614cd /Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs
parentd9fac68e24306673ff27e9f1c909a6f600d8dee0 (diff)
feat:合并伤害体积
Diffstat (limited to 'Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs')
-rw-r--r--Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs b/Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs
new file mode 100644
index 0000000..c301d4a
--- /dev/null
+++ b/Assets/Scripts/DamageVolumeSystem/SimpleHealth.cs
@@ -0,0 +1,55 @@
+using System;
+using UnityEngine;
+
+namespace DamageVolumeSystem
+{
+ [RequireComponent(typeof(Rigidbody))]
+ public class SimpleHealth : MonoBehaviour
+ {
+ public int max = 10000;
+ public int health = 10000;
+
+ private Rigidbody _rigidbody;
+
+ private void Start()
+ {
+ _rigidbody = GetComponent<Rigidbody>();
+ }
+
+ public void Damage(Damage amount)
+ {
+ health -= amount.Force;
+ health = Mathf.Clamp(health, 0, max);
+
+ _rigidbody.AddForce(amount.Direction * amount.Force / 200);
+ }
+
+ public void Heal(Damage amount)
+ {
+ health += amount.Force;
+ health = Mathf.Clamp(health, 0, max);
+ }
+
+ private void OnDrawGizmos()
+ {
+ var t = transform;
+ var size = (t.lossyScale.x + t.lossyScale.y + t.lossyScale.z) / 3;
+
+ Gizmos.matrix = t.localToWorldMatrix;
+
+ Gizmos.DrawWireCube(new Vector3(0, size, 0), new Vector3(
+ 2 / t.lossyScale.x,
+ 0.5f / t.lossyScale.y,
+ 0.5f / t.lossyScale.z
+ ) * size);
+
+ Gizmos.color = new Color(1f, 0.44f, 0.37f);
+
+ Gizmos.DrawCube(new Vector3(0, size, 0), new Vector3(
+ 2 / t.lossyScale.x * ((float) health / max),
+ 0.5f / t.lossyScale.y,
+ 0.5f / t.lossyScale.z
+ ) * size * 0.8f);
+ }
+ }
+}