Unity3D跟随路径移动
在做项目的时候,突然想到要做一个可以跟随路径走的AI,而且路径可视化。
原视频地址:https://www.youtube.com/watch?v=1aBjTa3xQzE
分为两部分代码,第一个是编辑路径的代码,另一个为跟随路径的代码。
代码如下
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EditorPathScript : MonoBehaviour {
public Color rayColor = Color.white;
public List<Transform> path_objs = new List<Transform>();
Transform[] theArray;
void OnDrawGizmos(){
Gizmos.color = rayColor;
theArray = GetComponentsInChildren<Transform>();
path_objs.Clear();
foreach(Transform path_obj in theArray){
if(path_obj != this.transform){
path_objs.Add(p