GetRemainingDistance может быть вызван только активным агентом, который был помещен на NavmeshC#

Место общения программистов C#
Ответить
Anonymous
 GetRemainingDistance может быть вызван только активным агентом, который был помещен на Navmesh

Сообщение Anonymous »

У меня есть две ошибки: < /p>

Первая ошибка: < /p>



missomconconentexception: нет «Navmeshagent '». Вам, вероятно, нужно добавить Navmeshagent в игровой объект
"ThirdPersonController". Или ваш скрипт должен проверить, подключен ли компонент
перед его использованием. Patroll.cs < /p>

using UnityEngine;
using System.Collections;

public class Patroll : MonoBehaviour {

public Transform[] points;
private int destPoint = 0;
private NavMeshAgent agent;

// Use this for initialization
void Start () {

agent = GetComponent();

// 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.Length == 0)
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.Length;
}

void Update () {
// Choose the next destination point when the agent gets
// close to the current one.
if (agent.remainingDistance < 0.5f)
GotoNextPoint();
}
}
< /code>

строка 41 is: < /p>

if (agent.remainingDistance < 0.5f)
< /code>

This Script Patroll.cs Я перетащил в иерархию в ThirdPersonController. < /p>

Затем, после этого у меня есть еще одна ошибка, и эта ошибка, которую я также имел даже до того, как я создал скрипт patroll.cs: < /p>



был размещен на Navmesh.
UnityEngine.navmeshagent: get_remainingDistance ()
unitystandardassets.characters.thirdperson.aicharactercontrol: update ()
(at atsets /standard
Assets/символы/третья personcharacter/scripts/aicharactercontrol.cs: 31)


Эта ошибка находится в скрипте aicharactercontrol.cs. 31: < /p>

if (agent.remainingDistance > agent.stoppingDistance)
< /code>

То, что я пытался сделать до сих пор, чтобы исправить это в Unity. Я нажал на меню по компоненту> Навигации> Агент Navmesh < /p>

Теперь он добавлен в третий PersonController Агент NAV NESH, и я могу видеть в инспекторе третьего спектакля. Aicharactercontrol.cs script < /p>

using System;
using UnityEngine;

namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding
public ThirdPersonCharacter character { get; private set; } // the character we are controlling
public Transform target; // target to aim for

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();
character = GetComponent();

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;
}
}
}
< /code>

Я не могу понять, как исправить ошибки. < /p>

Подробнее здесь: https://stackoverflow.com/questions/385 ... een-placed
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»