2016-07-23 20 views
1

に置かれている活性剤で呼び出すことができます:最初のエラーがあるGetRemainingDistanceだけ私は2つのエラー持っNavMesh

を:

MissingComponentException:NO「NavMeshAgent」添付はありません "ThirdPersonController"ゲームオブジェクトに、スクリプトが にアクセスしようとしています。おそらく、NavMeshAgentをゲームオブジェクト "ThirdPersonController"に追加する必要があります。または、スクリプトを使用する前に コンポーネントが接続されているかどうかを確認する必要があります。

(資産/マイスクリプト/ Patroll.csで:41)Patroll.Update()

Patroll.Updateと呼ばれる、私が作成したスクリプトファイルである:Patroll.cs

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<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.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(); 
    } 
} 

ライン41は以下のとおりです。私はThirdPersonControllerに階層にオーバードラッグPatroll.cs

if (agent.remainingDistance < 0.5f) 

このスクリプト。

「GetRemainingDistance」のみ が上に置かれている活性剤で呼び出すことができます。

は、この後、私は別のエラーと私はPatroll.csスクリプトを作成する前に、私はまたしても持っていた、このエラーが発生していますNavMesh。 UnityEngine.NavMeshAgent:get_remainingDistance() UnityStandardAssets.Characters.ThirdPerson.AICharacterControl:更新(資産/標準 資産/文字/ ThirdPersonCharacter /スクリプト/ AICharacterControl.csで:31)()

このエラーでありますスクリプトAICharacterControl.csでは、これは統一スクリプトであり、階層内のThirdPersonControllerにも関連しています。

31行目:

if (agent.remainingDistance > agent.stoppingDistance) 

私はそれが団結している修正するために、これまでに実行しようとしました何。コンポーネント>ナビゲーション> NavMeshエージェントのメニューをクリックしました

これでNav NeshエージェントのThirdPersonControllerが追加され、ThirdPersonControllerのインスペクタでNav Nesh Agentパートが表示されます。

しかし、エラーはまだ存在します。

これは私がエラーを修正する方法を見つけ出すことはできませんAICharacterControl.csスクリプト

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

です。

答えて

0

ゲームで同じ問題が発生しました。それは、実行時にキャラクタ・プレハブをロードしたときに起こったことです。私の古いマップのプレハブには異なる位置があります。これを修正するには、ナビゲーションメッシュにプレハブを置き、プレハブを保存します。

関連する問題