Как мне соединить две системы путевых точек? - PullRequest
0 голосов
/ 27 августа 2018

введите код здесь

List<Transform> points = new List <Transform> ();

private int destPoint = 0;
private UnityEngine.AI.NavMeshAgent agent;

public WaypointSystem path;
//Assembly-CSharp-firstpass
public float remainingDistance = 0.3f;

void Start () {

    points = path.waypoints;

    agent = GetComponent<UnityEngine.AI.NavMeshAgent>();

    // Disabling auto-braking allows for continuous movement
    // between points (ie, the agent doesn't slow down as it
    // approaches a destination point).

       // agent.autoBraking = false;


    //GotoNextPoint();
}


void GotoNextPoint() {
    // Returns if no points have been set up
    if (points.Count == 0)
        return;
    if (destPoint == points.Count) return;

    // Set the agent to go to the currently selected destination.
    agent.destination = points[destPoint].position;


    // Choose the next point in the array as the destination,
    // cycling to the start if necessary.
    //destPoint = (destPoint + 1) % points.Count;
    destPoint = (destPoint + 1);


}


void Update()
{
    // Choose the next destination point when the agent gets
    // close to the current one.
    if (agent.remainingDistance < remainingDistance)
    {
        GotoNextPoint();
    }
   if(destpoint==8)
   agent.enabled=false;


}
}

Я хочу подключить две системы wayPoint.Когда игрок (агент) достигает последней точки первой системы wayPoint, она следует за второй путевой точкой, возможно ли это?В этом коде я отключаю агента navmesh после достижения последней точки первой системы путевых точек и через несколько секунд включается ее получение, но игрок возвращается обратно к первой точке первой системы wayPoint, он не может перейти ко второй

1 Ответ

0 голосов
/ 27 августа 2018

Я не знаком с системами путевых точек, но разве ты не можешь просто изменить переменную точек на новую систему путевых точек waypoints, когда ты отреагировал на последнюю точку (это можно проверить в GotoNextPoint. Может быть, что-то вроде этого:

void GotoNextPoint() {
// Returns if no points have been set up
if (points.Count == 0)
    return;
if (destPoint == points.Count)
{
    points = otherPath.waypoints;
    destPoint = 0;
    return;
}

Не забудьте сбросить destPoint на 0, чтобы агент navmesh запускался с первого элемента 2-й системы точек. Надеюсь, это поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...