Compare commits

..

No commits in common. "436b55ebb158d8705d2fe28e8fcdf43aab124f87" and "073f34d88833b7eb022a3ea1340ddecf0f463881" have entirely different histories.

3 changed files with 22 additions and 58 deletions

View File

@ -1485,30 +1485,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ea3c4e24ebc42194181651236cdf30f1, type: 3}
m_Name:
m_EditorClassIdentifier:
npcId:
nstate: 1
target: {fileID: 0}
currentTarget: {x: 0, y: 0, z: 0}
targetPoints: []
--- !u!195 &3307599082991733569
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9144465012532105757}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4

View File

@ -27283,9 +27283,5 @@ PrefabInstance:
propertyPath: m_Name
value: Vang
objectReference: {fileID: 0}
- target: {fileID: 9144465012532105757, guid: 4bc999dc543a61148a0ba3bb1dd45a4d, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4bc999dc543a61148a0ba3bb1dd45a4d, type: 3}

View File

@ -2,7 +2,6 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.AI;
public enum Npcstate
{
@ -13,8 +12,6 @@ public enum Npcstate
public class RecuseNpc : MonoBehaviour
{
private NavMeshAgent navMeshAgent;//navmesh组件
public string npcId;
public static RecuseNpc instance;
@ -32,7 +29,7 @@ public class RecuseNpc : MonoBehaviour
public Vector3 currentTarget;
// <EFBFBD>洢Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>List
// 存储目标点的List
public List<Vector3> targetPoints = new List<Vector3>();
private void Awake()
@ -41,17 +38,9 @@ public class RecuseNpc : MonoBehaviour
recusebtn = GameObject.Find("Canvas/Recuse").GetComponent<Button>();
anim = this.GetComponent<Animator>();
navMeshAgent = GetComponent<NavMeshAgent>();
// 初始化 NavMeshAgent 的一些属性
navMeshAgent.speed = 3.5f; // 设置速度
navMeshAgent.acceleration = 8f; // 设置加速度
navMeshAgent.angularSpeed = 120f; // 设置旋转速度
navMeshAgent.stoppingDistance = 1f; // 设置停止的距离
}
private void OnTriggerEnter(Collider other)//ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ľ<EFBFBD>Ԯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ǩ<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>UI
private void OnTriggerEnter(Collider other)//通过触发器得到对应的救援组人员标签是否显现出UI
{
if(other.tag == "Player")
recusebtn.gameObject.SetActive(true);
@ -69,51 +58,51 @@ public class RecuseNpc : MonoBehaviour
npcId = id;
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<EFBFBD><EFBFBD>״̬
public void Setnpcstate()//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԯ<EFBFBD><EFBFBD>ťִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>԰<EFBFBD>ť<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//设置NPC的状态
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
{
movebool = true;
nstate = Npcstate.run;
recusebtn.gameObject.SetActive(false);
Debug.Log("Setnpcstate<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
Debug.Log("Setnpcstate调用");
}
//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>
//设置NPC的目标点
public void SetNpcDes(Vector3 tar)
{
//target.position = tar;
targetPoints.Add(tar); // <EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD>б<EFBFBD><EFBFBD><EFBFBD>
targetPoints.Add(tar); // 将目标点添加到列表中
}
private void Update()
{
if (targetPoints.Count > 0) // 确保列表中有目标点
if (targetPoints.Count > 0) // 确保列表中有目标点
{
currentTarget = targetPoints[0]; // 获取当前的目标点
currentTarget = targetPoints[0]; // 获取当前的目标点
// 判断是否到达目标点
if (movebool && navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance)
if (Vector3.Distance(transform.position, currentTarget) < 1.3f && movebool && currentTarget != null) // 判断人物被救援后移动到目标位置
{
Debug.Log("到达目标点");
Debug.Log("到达目标点");
// 达到目标后,从列表中移除该目标点
// 达到目标后,从列表中移除该目标点
if(targetPoints.Count > 1)
{
targetPoints = RemoveDes();
}
else
{
targetPoints.Clear(); // 清空列表
targetPoints = null;
}
// 设置NPC状态
// 设置NPC状态
nstate = Npcstate.idle;
movebool = false;
}
}
// 继续处理NPC的状态和动画
// 继续处理NPC的状态和动画
switch (nstate)
{
case Npcstate.idle:
@ -129,7 +118,7 @@ public class RecuseNpc : MonoBehaviour
}
}
//移除第一个
//删除目标
public List<Vector3> RemoveDes()
{
List<Vector3> list = new List<Vector3>();
@ -143,12 +132,14 @@ public class RecuseNpc : MonoBehaviour
}
//跑步逻辑
public void Run(Vector3 target)
{
if (movebool)
{
SetAni(1);
navMeshAgent.SetDestination(target); // 使用 NavMeshAgent 设置目标点
transform.LookAt(target);
transform.position = Vector3.Lerp(transform.position, target, 0.3f * Time.deltaTime);
}
}