代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class AIEnemy : MonoBehaviour
{
private NavMeshAgent nav; public GameObject targetPos; public bool isNavGuide
= true; public float catchDis = 20.0f; public int enemySpeed = 15; public
AIVehicle aIVehicle; private Rigidbody rig; void Start() { nav =
this.transform.GetComponent<NavMeshAgent>(); targetPos =
GameObject.FindGameObjectWithTag("Player"); aIVehicle =
targetPos.GetComponent<AIVehicle>(); } void Update() { if (isNavGuide != false
&& aIVehicle.currentLap != 1) { CalEnemyToPlayer(); } } public void
CalEnemyToPlayer() { try { nav.enabled = true; nav.speed = enemySpeed;
transform.LookAt(targetPos.transform);
nav.SetDestination(targetPos.transform.position); float dis =
Vector3.Distance(this.transform.position, targetPos.transform.position);
//float dis = nav.remainingDistance; if (dis < catchDis+10) {
aIVehicle.isGameOver = true; //nav.acceleration = -(nav.speed/5.0f); isNavGuide
= false; StartCoroutine(StopNav()); nav.speed = Mathf.MoveTowards(nav.speed, 0,
1.0f); Debug.Log("Game Over..."); } } catch (System.Exception e) {
Debug.Log("The Err is:" + e); } } IEnumerator StopNav() { yield return new
WaitForSeconds(1.1f); nav.isStopped = true; nav.enabled = false;
Debug.Log("Stop Nav..."); }
}

技术
©2019-2020 Toolsou All rights reserved,
vue项目中对axios的全局封装单个按键控制多种流水灯状态软件测试之BUG描述随机森林篇 R语言实现TP6验证器的使用示例及正确验证数据C语言编程之查找某学号学生成绩一文揭秘阿里、腾讯、百度的薪资职级c语言的5种常用排序方法2021年1月程序员工资统计,平均14915元Bug数能否做为技术人员考核的KPI?