_xiaofang/xiaofang/Assets/Script/Item/Fire.cs

218 lines
5.5 KiB
C#
Raw Normal View History

2024-10-21 10:08:49 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-10-23 20:48:23 +08:00
public enum Firestate
{
ExtinguishFire,//<2F><><EFBFBD><EFBFBD>
NotExtinguishFire//δ<><CEB4><EFBFBD><EFBFBD>
}
2024-10-21 10:08:49 +08:00
public class Fire : MonoBehaviour
{
2024-10-23 20:48:23 +08:00
2024-10-21 10:08:49 +08:00
private bool isPlayerInRange = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ڷ<EFBFBD>Χ<EFBFBD><CEA7>
private bool isExtinguishing = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-05 09:21:07 +08:00
public float extinguishTime = 3f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
2024-10-21 10:08:49 +08:00
private float holdTime = 0f; // <20><>ס<EFBFBD><D7A1>ť<EFBFBD>ļ<EFBFBD>ʱ
2024-12-04 16:40:48 +08:00
public float fireHurt = 10f;
2024-11-07 19:13:50 +08:00
2024-12-04 16:40:48 +08:00
public float dis;
public float maxfiredis = 2f;
2024-12-05 09:21:07 +08:00
public float firedis = 4f;
2024-12-04 16:40:48 +08:00
public PlayerState ps;
public UseSkill us;
float timer = 0;
2024-11-06 11:28:04 +08:00
//private Firestate firestate = Firestate.NotExtinguishFire;
2024-12-04 16:40:48 +08:00
2024-10-21 10:08:49 +08:00
private CharacterControl characterControl;//<2F><><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD>
void Start()
{
2024-12-04 16:40:48 +08:00
us = GameObject.Find("player").GetComponent<UseSkill>();
ps = GameObject.Find("player").GetComponent<PlayerState>();
2024-10-21 10:08:49 +08:00
}
2024-10-24 09:23:47 +08:00
2024-10-21 10:08:49 +08:00
void Update()
2024-11-07 19:13:50 +08:00
{
2024-12-05 09:21:07 +08:00
HurtPeople();
2024-12-04 10:58:48 +08:00
if (us.currentItem == null)
2024-12-04 16:40:48 +08:00
{
return;
}
else if(us.currentItem.transform.name != "NoFire")
2024-12-04 16:40:48 +08:00
{
return;
2024-12-04 16:40:48 +08:00
}
MieFire();
2024-11-07 19:13:50 +08:00
}
2024-12-04 16:40:48 +08:00
public void HurtPeople()
{
2024-12-05 09:21:07 +08:00
dis = Vector3.Distance(GameObject.Find("player").transform.position, this.transform.position);
2024-12-04 16:40:48 +08:00
2024-12-05 09:21:07 +08:00
if(dis<maxfiredis)
2024-12-04 16:40:48 +08:00
{
2024-12-05 09:21:07 +08:00
timer += Time.deltaTime;
//Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѫ");
if (timer > 1f)
{
//Debug.Log("================================================");
ps.beHurt(fireHurt);
timer = 0;
}
2024-12-04 16:40:48 +08:00
}
}
2024-11-07 19:13:50 +08:00
2024-11-18 17:19:35 +08:00
public void MieFire()
2024-10-21 10:08:49 +08:00
{
2024-12-05 09:21:07 +08:00
//// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ڷ<EFBFBD>Χ<EFBFBD><CEA7><EFBFBD>Ұ<EFBFBD>ס<EFBFBD><D7A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//if (isPlayerInRange && Input.GetMouseButton(0))
//{
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
// if (!isExtinguishing)
// DisablePlayerControl();
// holdTime += Time.deltaTime;
// Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>" + holdTime);
// if (holdTime >= extinguishTime && !isExtinguishing)
// {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD>ס<EFBFBD><D7A1><EFBFBD>ﵽָ<EFB5BD><D6B8>ʱ<EFBFBD>䣬ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
// StopFire();
// isExtinguishing = true; // <20><>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// }
//}
//else
//{
// //Debug.Log("<22>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD><EFBFBD>");
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>ʱ
// holdTime = 0f;
// isExtinguishing = false;
// // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD>
// if (!Input.GetMouseButton(0)) EnablePlayerControl();
//}
2024-10-21 10:08:49 +08:00
if (isPlayerInRange && Input.GetMouseButton(0))
{
2024-12-05 09:21:07 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ľ<EFBFBD><C4BE><EFBFBD>
dis = Vector3.Distance(GameObject.Find("player").transform.position, this.transform.position);
2024-10-21 10:08:49 +08:00
2024-12-05 09:21:07 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҿ<EFBFBD><D2BE><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><E3B9BB><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (dis <= firedis)
2024-10-21 10:08:49 +08:00
{
2024-12-05 09:21:07 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
if (!isExtinguishing)
DisablePlayerControl();
holdTime += Time.deltaTime;
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>" + holdTime);
if (holdTime >= extinguishTime && !isExtinguishing)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ұ<EFBFBD>ס<EFBFBD><D7A1><EFBFBD>ﵽָ<EFB5BD><D6B8>ʱ<EFBFBD>䣬ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
StopFire();
isExtinguishing = true; // <20><>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
2024-10-21 10:08:49 +08:00
}
}
2024-11-07 19:13:50 +08:00
else
2024-10-21 10:08:49 +08:00
{
2024-12-05 09:21:07 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>ʱ
2024-10-21 10:08:49 +08:00
holdTime = 0f;
isExtinguishing = false;
// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD>
if (!Input.GetMouseButton(0)) EnablePlayerControl();
2024-10-21 10:08:49 +08:00
}
2024-12-04 16:40:48 +08:00
2024-10-21 10:08:49 +08:00
}
2024-11-07 19:13:50 +08:00
2024-10-21 10:08:49 +08:00
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
public void StartFire()
{
2024-10-23 20:48:23 +08:00
this.gameObject.SetActive(true);
2024-10-21 10:08:49 +08:00
isExtinguishing = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
}
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
public void StopFire()
{
2024-10-23 20:48:23 +08:00
this.characterControl.Restore();
this.gameObject.SetActive(false);
2024-10-21 10:08:49 +08:00
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD>Ϩ<EFBFBD><CFA8>");
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χʱ<CEA7><CAB1><EFBFBD><EFBFBD>
private void OnTriggerEnter(Collider other)
{
2024-12-05 09:21:07 +08:00
//if (other.CompareTag("Player"))
//{
// isPlayerInRange = true; // <20><><EFBFBD>ҽ<EFBFBD><D2BD>Χ
// characterControl = other.GetComponent<CharacterControl>();
//}
2024-10-21 10:08:49 +08:00
if (other.CompareTag("Player"))
{
isPlayerInRange = true; // <20><><EFBFBD>ҽ<EFBFBD><D2BD>Χ
characterControl = other.GetComponent<CharacterControl>();
2024-12-05 09:21:07 +08:00
// <20><><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD>˴<EFBFBD><CBB4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>Χ
float playerDistance = Vector3.Distance(other.transform.position, this.transform.position);
if (playerDistance <= maxfiredis)
{
isPlayerInRange = true;
}
else
{
isPlayerInRange = false;
}
2024-10-21 10:08:49 +08:00
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA><EFBFBD>Χʱ<CEA7><CAB1><EFBFBD><EFBFBD>
private void OnTriggerExit(Collider other)
{
2024-12-05 09:21:07 +08:00
//if (other.CompareTag("Player"))
//{
// isPlayerInRange = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>Χ
// characterControl = null;
//}
2024-10-21 10:08:49 +08:00
if (other.CompareTag("Player"))
{
isPlayerInRange = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA>Χ
characterControl = null;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD>
private void DisablePlayerControl()
{
if (characterControl != null)
{
characterControl.enabled = false;
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF><EFBFBD><EFBFBD><EFBFBD>
private void EnablePlayerControl()
{
if (characterControl != null)
{
characterControl.enabled = true;
}
}
}