This commit is contained in:
huyulong 2024-12-05 09:21:07 +08:00
parent 1d623866c4
commit 13f74a2139
5 changed files with 98 additions and 36 deletions

View File

@ -38841,6 +38841,11 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
extinguishTime: 3 extinguishTime: 3
fireHurt: 10
dis: 0
maxfiredis: 2
ps: {fileID: 0}
us: {fileID: 0}
--- !u!135 &5825030608256766515 --- !u!135 &5825030608256766515
SphereCollider: SphereCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -38852,5 +38857,5 @@ SphereCollider:
m_IsTrigger: 1 m_IsTrigger: 1
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Radius: 1.5 m_Radius: 3
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}

View File

@ -2995,7 +2995,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
totalHp: 100 totalHp: 100
currentHp: 100 currentHp: 0
defend: 0 defend: 0
--- !u!1001 &383747424 --- !u!1001 &383747424
PrefabInstance: PrefabInstance:
@ -13591,9 +13591,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
extinguishTime: 3 extinguishTime: 3
fireHurt: 10
dis: 0 dis: 0
maxfiredis: 0 maxfiredis: 0
playerObj: {fileID: 0} ps: {fileID: 0}
us: {fileID: 0} us: {fileID: 0}
--- !u!135 &1629676688 --- !u!135 &1629676688
SphereCollider: SphereCollider:

View File

@ -177,9 +177,9 @@ public class CharacterAin : MonoBehaviour
} }
} }
IEnumerator jiutimer(float timer) //IEnumerator jiutimer(float timer)
{ //{
yield return new WaitForSeconds(timer); // yield return new WaitForSeconds(timer);
} //}
} }

View File

@ -13,13 +13,14 @@ public class Fire : MonoBehaviour
private bool isPlayerInRange = false; // 检查玩家是否在范围内 private bool isPlayerInRange = false; // 检查玩家是否在范围内
private bool isExtinguishing = false; // 是否正在灭火 private bool isExtinguishing = false; // 是否正在灭火
public float extinguishTime = 3.0f; // 灭火所需的时间 public float extinguishTime = 3f; // 灭火所需的时间
private float holdTime = 0f; // 按住按钮的计时 private float holdTime = 0f; // 按住按钮的计时
public float fireHurt = 10f; public float fireHurt = 10f;
public float dis; public float dis;
public float maxfiredis = 2f; public float maxfiredis = 2f;
public float firedis = 4f;
public PlayerState ps; public PlayerState ps;
@ -38,8 +39,10 @@ public class Fire : MonoBehaviour
void Update() void Update()
{ {
HurtPeople();
HurtPeople();
if (us.currentItem.transform.name != "NoFire" || us.currentItem == null) if (us.currentItem.transform.name != "NoFire" || us.currentItem == null)
{ {
return; return;
@ -53,55 +56,84 @@ public class Fire : MonoBehaviour
public void HurtPeople() public void HurtPeople()
{ {
dis = Vector3.Distance(GameObject.Find("player").transform.position, this.transform.position);
timer += Time.deltaTime; if(dis<maxfiredis)
Debug.Log("进入扣血");
if(timer > 1f)
{ {
Debug.Log("================================================"); timer += Time.deltaTime;
ps.beHurt(fireHurt); //Debug.Log("进入扣血");
timer = 0; if (timer > 1f)
{
//Debug.Log("================================================");
ps.beHurt(fireHurt);
timer = 0;
}
} }
} }
public void MieFire() public void MieFire()
{ {
//// 检查玩家是否在范围内且按住灭火键
//if (isPlayerInRange && Input.GetMouseButton(0))
//{
// // 禁用玩家控制器,防止玩家移动
// if (!isExtinguishing)
// DisablePlayerControl();
// holdTime += Time.deltaTime;
// Debug.Log("灭火计时:" + holdTime);
// if (holdTime >= extinguishTime && !isExtinguishing)
// 检查玩家是否在范围内且按住灭火键 // {
// // 如果玩家按住键达到指定时间,停止火焰
// StopFire();
// isExtinguishing = true; // 防止重复触发灭火
// }
//}
//else
//{
// //Debug.Log("松开按键");
// // 如果玩家松开按键或者离开范围,重置计时
// holdTime = 0f;
// isExtinguishing = false;
// // 恢复玩家控制器
// if (!Input.GetMouseButton(0)) EnablePlayerControl();
//}
if (isPlayerInRange && Input.GetMouseButton(0)) if (isPlayerInRange && Input.GetMouseButton(0))
{ {
// 禁用玩家控制器,防止玩家移动 // 计算玩家与火源的距离
if (!isExtinguishing) dis = Vector3.Distance(GameObject.Find("player").transform.position, this.transform.position);
DisablePlayerControl();
holdTime += Time.deltaTime; // 如果玩家距离火源足够近且按下鼠标左键才触发灭火
Debug.Log("灭火计时:" + holdTime); if (dis <= firedis)
if (holdTime >= extinguishTime && !isExtinguishing)
{ {
// 如果玩家按住键达到指定时间,停止火焰 // 禁用玩家控制器,防止玩家移动
StopFire(); if (!isExtinguishing)
isExtinguishing = true; // 防止重复触发灭火 DisablePlayerControl();
holdTime += Time.deltaTime;
Debug.Log("灭火计时:" + holdTime);
if (holdTime >= extinguishTime && !isExtinguishing)
{
// 如果玩家按住键达到指定时间,停止火焰
StopFire();
isExtinguishing = true; // 防止重复触发灭火
}
} }
} }
else else
{ {
//Debug.Log("松开按键"); // 如果松开按键或者离开范围,重置计时
// 如果玩家松开按键或者离开范围,重置计时
holdTime = 0f; holdTime = 0f;
isExtinguishing = false; isExtinguishing = false;
// 恢复玩家控制器 // 恢复玩家控制器
if (!Input.GetMouseButton(0)) EnablePlayerControl(); if (!Input.GetMouseButton(0)) EnablePlayerControl();
} }
} }
@ -125,17 +157,38 @@ public class Fire : MonoBehaviour
// 当玩家进入火焰范围时触发 // 当玩家进入火焰范围时触发
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
//if (other.CompareTag("Player"))
//{
// isPlayerInRange = true; // 玩家进入范围
// characterControl = other.GetComponent<CharacterControl>();
//}
if (other.CompareTag("Player")) if (other.CompareTag("Player"))
{ {
isPlayerInRange = true; // 玩家进入范围 isPlayerInRange = true; // 玩家进入范围
characterControl = other.GetComponent<CharacterControl>(); characterControl = other.GetComponent<CharacterControl>();
// 可以调整此处的触发范围
float playerDistance = Vector3.Distance(other.transform.position, this.transform.position);
if (playerDistance <= maxfiredis)
{
isPlayerInRange = true;
}
else
{
isPlayerInRange = false;
}
} }
} }
// 当玩家离开火焰范围时触发 // 当玩家离开火焰范围时触发
private void OnTriggerExit(Collider other) private void OnTriggerExit(Collider other)
{ {
//if (other.CompareTag("Player"))
//{
// isPlayerInRange = false; // 玩家离开范围
// characterControl = null;
//}
if (other.CompareTag("Player")) if (other.CompareTag("Player"))
{ {
isPlayerInRange = false; // 玩家离开范围 isPlayerInRange = false; // 玩家离开范围

View File

@ -27,8 +27,11 @@ public class PlayerState : MonoBehaviour
public void beHurt(float hurt) public void beHurt(float hurt)
{ {
currentHp -= hurt; if(currentHp >0)
Debug.Log(currentHp); {
currentHp -= hurt;
Debug.Log(currentHp);
}
if(currentHp <= 0) if(currentHp <= 0)
{ {
Debug.Log("你死了"); Debug.Log("你死了");