From 3e3888fb9cc5d63d2b8e1b4f32e3ad179d219716 Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Wed, 4 Dec 2024 16:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A3=E8=A1=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/Scenes/Tmap 1.unity | 20 ++++++++ xiaofang/Assets/Script/Item/Fire.cs | 48 +++++++++++++++++-- .../Assets/Script/hylScripts/PlayerState.cs | 10 ++-- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/xiaofang/Assets/Scenes/Tmap 1.unity b/xiaofang/Assets/Scenes/Tmap 1.unity index 04eac5fb..2474e4a7 100644 --- a/xiaofang/Assets/Scenes/Tmap 1.unity +++ b/xiaofang/Assets/Scenes/Tmap 1.unity @@ -2792,6 +2792,7 @@ GameObject: - component: {fileID: 382802819} - component: {fileID: 382802818} - component: {fileID: 382802821} + - component: {fileID: 382802822} m_Layer: 0 m_Name: player m_TagString: Player @@ -2981,6 +2982,21 @@ MonoBehaviour: m_EditorClassIdentifier: cha: {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 PrefabInstance: m_ObjectHideFlags: 0 @@ -13575,6 +13591,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: extinguishTime: 3 + dis: 0 + maxfiredis: 0 + playerObj: {fileID: 0} + us: {fileID: 0} --- !u!135 &1629676688 SphereCollider: m_ObjectHideFlags: 0 diff --git a/xiaofang/Assets/Script/Item/Fire.cs b/xiaofang/Assets/Script/Item/Fire.cs index 1d166f40..dbb26f57 100644 --- a/xiaofang/Assets/Script/Item/Fire.cs +++ b/xiaofang/Assets/Script/Item/Fire.cs @@ -15,34 +15,70 @@ public class Fire : MonoBehaviour private bool isExtinguishing = false; // 是否正在灭火 public float extinguishTime = 3.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 CharacterControl characterControl;//玩家控制器 void Start() { - - + us = GameObject.Find("player").GetComponent(); + ps = GameObject.Find("player").GetComponent(); } void Update() { + HurtPeople(); + if (us.currentItem.transform.name != "NoFire" || us.currentItem == null) + { + return; + } + else + { MieFire(); + } + } + public void HurtPeople() + { + + + timer += Time.deltaTime; + Debug.Log("进入扣血"); + if(timer > 1f) + { + Debug.Log("================================================"); + ps.beHurt(fireHurt); + timer = 0; + } + + } public void MieFire() { + + + + // 检查玩家是否在范围内且按住灭火键 if (isPlayerInRange && Input.GetMouseButton(0)) { // 禁用玩家控制器,防止玩家移动 - if (!isExtinguishing) + if (!isExtinguishing) DisablePlayerControl(); holdTime += Time.deltaTime; @@ -64,6 +100,8 @@ public class Fire : MonoBehaviour // 恢复玩家控制器 if (!Input.GetMouseButton(0)) EnablePlayerControl(); } + + } diff --git a/xiaofang/Assets/Script/hylScripts/PlayerState.cs b/xiaofang/Assets/Script/hylScripts/PlayerState.cs index 0ed3f920..954962bb 100644 --- a/xiaofang/Assets/Script/hylScripts/PlayerState.cs +++ b/xiaofang/Assets/Script/hylScripts/PlayerState.cs @@ -6,7 +6,7 @@ public class PlayerState : MonoBehaviour { [Header("玩家总血量")] - public float totalHp; + public float totalHp = 100; [Header("玩家当前血量")] public float currentHp; [Header("抵抗力")] @@ -16,7 +16,7 @@ public class PlayerState : MonoBehaviour // Start is called before the first frame update void Start() { - + currentHp = totalHp; } // Update is called once per frame @@ -25,10 +25,10 @@ public class PlayerState : MonoBehaviour } - public void beHurt(int hurt) + public void beHurt(float hurt) { - - Debug.Log(currentHp -= hurt); + currentHp -= hurt; + Debug.Log(currentHp); if(currentHp <= 0) { Debug.Log("你死了");