简单导航
在人物下创建RunTest,输入代码,并创建个Cube,将Cube拖拽到如下图所示。
using UnityEngine;
using System.Collections;
public class RunTest : MonoBehaviour
{
public Transform TargetObject = null;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (TargetObject != null)
GetComponent<UnityEngine.AI.NavMeshAgent>().destination = TargetObject.position;
}
}
点击Play,人物跟着Cube走。