秘密潜入敌人AI

#秘密潜入敌人AI

##巡逻主要代码

 using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.AI;

public class robot : MonoBehaviour {

public Vector3[] xunluo;

public GameObject mPlayer;

public enum RobotStatus

{

Idle,

Patrol,

Follow,

Attack,

};

public RobotStatus status=RobotStatus.Patrol;

public int i=0;

public NavMeshAgent mAgent;

public Animator ani;

private float ttt=2;

// Use this for initialization

void Start () {

mAgent = GetComponent ();

ani = GetComponent ();

mPlayer = GameObject.FindGameObjectWithTag ("player");

}

void Xunluo(){

mAgent.SetDestination (xunluo [i]);

if (Vector3.Distance (transform.position, xunluo [i]) < 0.4f)

{

ani.SetBool ("idle", true);

i = Random.Range (0, 4);

status = RobotStatus.Idle;

}

}

// Update is called once per frame

void Update () {

switch (status) {

case RobotStatus.Patrol:

Xunluo ();

break;

case RobotStatus.Idle:

if (ttt > 0) {

ttt -= Time.deltaTime;

} else {

ttt = 2;

status = RobotStatus.Patrol;

ani.SetBool ("idle", false);

}

break;

case RobotStatus.Follow:

break;

case RobotStatus.Attack:

break;

}

}

}

你可能感兴趣的:(秘密潜入敌人AI)