44 lines
948 B
C#
44 lines
948 B
C#
using UnityEngine;
|
|
|
|
public enum BodyPart
|
|
{
|
|
Head,
|
|
Body,
|
|
Leg
|
|
}
|
|
|
|
// 掛在機器人骨頭上的命中框 (Collider 要勾 Is Trigger)
|
|
public class Hitbox : MonoBehaviour
|
|
{
|
|
[Header("部位")]
|
|
public BodyPart part = BodyPart.Body;
|
|
|
|
private BotHealth owner;
|
|
|
|
void Awake()
|
|
{
|
|
owner = GetComponentInParent<BotHealth>();
|
|
}
|
|
|
|
// 部位傷害倍率 : 頭 ×1.5、身體 ×1、腿 ×0.7
|
|
public static float GetMultiplier(BodyPart part)
|
|
{
|
|
switch (part)
|
|
{
|
|
case BodyPart.Head: return 1.5f;
|
|
case BodyPart.Leg: return 0.7f;
|
|
default: return 1f;
|
|
}
|
|
}
|
|
|
|
// 回傳實際造成的傷害 (機器人已經倒下就回傳 0)
|
|
public float Hit(float baseDamage)
|
|
{
|
|
if (owner == null || owner.IsDead) return 0f;
|
|
|
|
float damage = baseDamage * GetMultiplier(part);
|
|
owner.TakeDamage(damage, part);
|
|
return damage;
|
|
}
|
|
}
|