天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.3 KiB

using UnityEngine;
using System.Collections;
/// <summary>
/// 寻路组件切换
/// </summary>
public class AgentSwitch : MonoBehaviour {
UnityEngine.AI.NavMeshAgent com_Agent;
UnityEngine.AI.NavMeshObstacle com_Obs;
bool isMove = false;
// Use this for initialization
void Start () {
com_Agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
com_Obs = GetComponent<UnityEngine.AI.NavMeshObstacle>();
}
// Update is called once per frame
void Update () {
switchNav();
}
private void switchNav()
{
if (!com_Agent.enabled)
{
return;
}
if (com_Agent.velocity.magnitude > 0)
{
isMove=true;
}
else {
if (isMove)
{
Delaynav();
}
}
}
public void Delaynav()
{
isMove = false;
GetComponent<Animator>().SetFloat("AD", 0);
GetComponent<Animator>().SetFloat("WS", 0);
StartCoroutine(delayNav());
}
IEnumerator delayNav()
{
com_Agent.enabled = false;
yield return null;
if (!com_Agent.enabled)
{
com_Obs.enabled = true;
}
else {
StartCoroutine(delayNav());
}
}
}