扣血逻辑

This commit is contained in:
huyulong 2024-12-04 16:40:48 +08:00
parent 358701471d
commit 3e3888fb9c
3 changed files with 68 additions and 10 deletions

View File

@ -2792,6 +2792,7 @@ GameObject:
- component: {fileID: 382802819} - component: {fileID: 382802819}
- component: {fileID: 382802818} - component: {fileID: 382802818}
- component: {fileID: 382802821} - component: {fileID: 382802821}
- component: {fileID: 382802822}
m_Layer: 0 m_Layer: 0
m_Name: player m_Name: player
m_TagString: Player m_TagString: Player
@ -2981,6 +2982,21 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
cha: {fileID: 0} cha: {fileID: 0}
xfs: {fileID: 0} xfs: {fileID: 0}
--- !u!114 &382802822
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 382802809}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 95a6a9a5d2e4ad24da328a2ea07ab37c, type: 3}
m_Name:
m_EditorClassIdentifier:
totalHp: 100
currentHp: 100
defend: 0
--- !u!1001 &383747424 --- !u!1001 &383747424
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -13575,6 +13591,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
extinguishTime: 3 extinguishTime: 3
dis: 0
maxfiredis: 0
playerObj: {fileID: 0}
us: {fileID: 0}
--- !u!135 &1629676688 --- !u!135 &1629676688
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -15,34 +15,70 @@ public class Fire : MonoBehaviour
private bool isExtinguishing = false; // 是否正在灭火 private bool isExtinguishing = false; // 是否正在灭火
public float extinguishTime = 3.0f; // 灭火所需的时间 public float extinguishTime = 3.0f; // 灭火所需的时间
private float holdTime = 0f; // 按住按钮的计时 private float holdTime = 0f; // 按住按钮的计时
public float fireHurt = 10f;
public float dis;
public float maxfiredis = 2f;
public PlayerState ps;
public UseSkill us;
float timer = 0;
//private Firestate firestate = Firestate.NotExtinguishFire; //private Firestate firestate = Firestate.NotExtinguishFire;
private CharacterControl characterControl;//玩家控制器 private CharacterControl characterControl;//玩家控制器
void Start() void Start()
{ {
us = GameObject.Find("player").GetComponent<UseSkill>();
ps = GameObject.Find("player").GetComponent<PlayerState>();
} }
void Update() void Update()
{ {
HurtPeople();
if (us.currentItem.transform.name != "NoFire" || us.currentItem == null)
{
return;
}
else
{
MieFire(); MieFire();
}
} }
public void HurtPeople()
{
timer += Time.deltaTime;
Debug.Log("½øÈë¿ÛѪ");
if(timer > 1f)
{
Debug.Log("================================================");
ps.beHurt(fireHurt);
timer = 0;
}
}
public void MieFire() public void MieFire()
{ {
// 检查玩家是否在范围内且按住灭火键 // 检查玩家是否在范围内且按住灭火键
if (isPlayerInRange && Input.GetMouseButton(0)) if (isPlayerInRange && Input.GetMouseButton(0))
{ {
// 禁用玩家控制器,防止玩家移动 // 禁用玩家控制器,防止玩家移动
if (!isExtinguishing) if (!isExtinguishing)
DisablePlayerControl(); DisablePlayerControl();
holdTime += Time.deltaTime; holdTime += Time.deltaTime;
@ -64,6 +100,8 @@ public class Fire : MonoBehaviour
// 恢复玩家控制器 // 恢复玩家控制器
if (!Input.GetMouseButton(0)) EnablePlayerControl(); if (!Input.GetMouseButton(0)) EnablePlayerControl();
} }
} }

View File

@ -6,7 +6,7 @@ public class PlayerState : MonoBehaviour
{ {
[Header("鯤소悧沂좆")] [Header("鯤소悧沂좆")]
public float totalHp; public float totalHp = 100;
[Header("鯤소뎠품沂좆")] [Header("鯤소뎠품沂좆")]
public float currentHp; public float currentHp;
[Header("둬예제")] [Header("둬예제")]
@ -16,7 +16,7 @@ public class PlayerState : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
currentHp = totalHp;
} }
// Update is called once per frame // Update is called once per frame
@ -25,10 +25,10 @@ public class PlayerState : MonoBehaviour
} }
public void beHurt(int hurt) public void beHurt(float hurt)
{ {
currentHp -= hurt;
Debug.Log(currentHp -= hurt); Debug.Log(currentHp);
if(currentHp <= 0) if(currentHp <= 0)
{ {
Debug.Log("콱价죄"); Debug.Log("콱价죄");