78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public enum Npcstate
|
||
{
|
||
idle,
|
||
dead,
|
||
healthy
|
||
}
|
||
|
||
public class RecuseNpc : MonoBehaviour
|
||
{
|
||
private Button recusebtn;
|
||
|
||
private bool statebool = false;
|
||
|
||
private Animator anim;
|
||
|
||
private Npcstate nstate = Npcstate.dead;
|
||
|
||
private bool movebool = false;
|
||
private Transform target;
|
||
private void Awake()
|
||
{
|
||
recusebtn = GameObject.Find("Canvas/Recuse").GetComponent<Button>();
|
||
anim = this.GetComponent<Animator>();
|
||
target = GameObject.Find("mubiao").GetComponent<Transform>();
|
||
}
|
||
|
||
private void OnTriggerEnter(Collider other)//通过触发器得到对应的救援组人员标签,是否显现出UI
|
||
{
|
||
if(other.name == "Man")
|
||
recusebtn.gameObject.SetActive(true);
|
||
if (statebool) return;
|
||
other.GetComponent<CharacterControl>().cha = this.gameObject ;
|
||
}
|
||
|
||
public void Setnpcstate()//点击救援按钮执行完动作后对按钮进行隐藏
|
||
{
|
||
movebool = true;
|
||
nstate = Npcstate.healthy;
|
||
recusebtn.gameObject.SetActive(false);
|
||
Debug.Log("Setnpcstate调用");
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (Vector3.Distance(transform.position,target.position) < 1.3f && movebool)//判断人物被救援后移动到目标位置
|
||
{
|
||
Debug.Log("到达目标点");
|
||
nstate = Npcstate.idle;
|
||
movebool = false;
|
||
}
|
||
|
||
|
||
switch (nstate)//通过枚举状态实现人物是否被救援,以及动作的改变
|
||
{
|
||
case Npcstate.idle:
|
||
anim.SetBool("Recuse", false);
|
||
break;
|
||
case Npcstate.healthy:
|
||
anim.SetBool("Recuse", true);
|
||
transform.LookAt(target);
|
||
transform.position = Vector3.Lerp(transform.position, target.position, 0.3f * Time.deltaTime);
|
||
break;
|
||
case Npcstate.dead:
|
||
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|