_xiaofang/xiaofang/Assets/Script/Character/Skills/Skill_watering.cs

96 lines
2.8 KiB
C#
Raw Normal View History

2024-10-21 10:08:49 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Skill_watering : MonoBehaviour
{
private CharacterAin CharacterAin;
public float detectionRadius = 10f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ķ<EFBFBD>Χ
public LayerMask fireLayerMask; // <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>
// Start is called before the first frame update
void Start()
{
CharacterAin = transform.GetComponent<CharacterAin>();
2024-12-02 19:44:46 +08:00
}
2024-10-21 10:08:49 +08:00
/// <summary>
/// <20><>ʼ<EFBFBD><CABC>ˮ
/// </summary>
/// <param name="currentItem"><3E><>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public void StartWatering(GameObject currentItem)
{
2024-12-24 10:58:23 +08:00
2024-10-21 10:08:49 +08:00
// <20><><EFBFBD><EFBFBD><E2B8BD><EFBFBD>Ļ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
2024-12-24 10:58:23 +08:00
DetectAndLookAtFire(currentItem);
2024-10-21 10:08:49 +08:00
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ
/// </summary>
/// <param name="currentItem">һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public void StopWatering(GameObject currentItem)
{
CharacterAin.SetSkillAin(CharacterSkill.NoSkill);
if (currentItem.GetComponent<NoFire>() != null)
{
currentItem.GetComponent<NoFire>().StopFire();
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD>Ļ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ý<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>Դ
/// </summary>
2024-12-24 10:58:23 +08:00
private void DetectAndLookAtFire(GameObject currentItem)
2024-10-21 10:08:49 +08:00
{
2024-12-24 10:58:23 +08:00
2024-10-21 10:08:49 +08:00
Collider[] objectsInRange = Physics.OverlapSphere(transform.position, detectionRadius, fireLayerMask);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>󣬲<EFBFBD><F3A3ACB2>ұ<EFBFBD>ǩΪ "fire" <20>Ķ<EFBFBD><C4B6><EFBFBD>
Collider nearestFire = null;
float minDistance = Mathf.Infinity;
foreach (Collider obj in objectsInRange)
{
if (obj.CompareTag("fire")) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>ǩ<EFBFBD><C7A9> "fire"
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
2024-12-24 17:55:44 +08:00
if (distance < detectionRadius)
2024-10-21 10:08:49 +08:00
{
nearestFire = obj;
minDistance = distance;
2024-12-24 10:58:23 +08:00
CharacterAin.SetSkillAin(CharacterSkill.Watering);
if (currentItem.GetComponent<NoFire>() != null)
{
currentItem.GetComponent<NoFire>().StartFire();
}
2024-12-24 17:55:44 +08:00
if (currentItem.gameObject.name == "gun")
{
XFS.instance.water.SetActive(true);
}
2024-10-21 10:08:49 +08:00
}
}
2024-12-24 17:55:44 +08:00
2024-10-21 10:08:49 +08:00
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>ý<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (nearestFire != null)
{
Vector3 directionToFire = (nearestFire.transform.position - transform.position).normalized;
directionToFire.y = 0; // <20><><EFBFBD>ֽ<EFBFBD>ɫ<EFBFBD><C9AB>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD>ϳ<EFBFBD><CFB3><EFBFBD><EFBFBD><EFBFBD>Դ
transform.forward = directionToFire;
2024-12-24 17:55:44 +08:00
if (currentItem.gameObject.name == "gun")
{
currentItem.transform.rotation = new Quaternion(61.7036781f, 186.325302f, 348.049622f, 0);
}
2024-10-21 10:08:49 +08:00
}
}
2024-10-21 10:08:49 +08:00
}