我想创建一个漫游AI。我正在使用Unity标准资产第三人称AI,但问题是AI只移动到某个特定点,并且无法在这些点之间巡逻。
以下是代码:
using System;
using UnityEngine;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (UnityEngine.AI.NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
// the navmesh agent required for the path finding
public UnityEngine.AI.NavMeshAgent agent { get; private set; }
// the character we are controlling
public ThirdPersonCharacter character { get; private set; }
// target to aim for
public Transform target;
private void Start()
{
// get the components on the object we need (should not be null
// due to require component so no need to check)
agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
}
private void Update()
{
if (target != null)
agent.SetDestination(target.position);
if (agent.remainingDistance > agent.stoppingDistance)
character.Move(agent.desiredVelocity, false, false);
else
character.Move(Vector3.zero, false, false);
}
public void SetTarget(Transform target)
{
this.target = target;
}
}
}
我该如何修改它以进行巡逻?