2017-10-04 3 views
0

最初のNavMeshAgentだけを作成できる問題があります。最初のNavMeshAgentだけを置くことができます

まず第一に、私はNavMeshベーク・オブジェクトのすべてのメッシュレンダラーを選択:

enter image description here

I微調整ベークビットを、それは細部のちょうど右の量を持っていたので。 Iは、バックランプ(白色球を有するもののいずれかの側に配置された2回の産卵を有する

enter image description here

:私は焼きエージェントオプションに大きな半径を使用した場合、様々なオブジェクトの周りの黒い隙間が大きくなりその中に)。これらは不可視ですが、スクリプトでは、NavMeshObjectsはある間隔でこれらの場所に配置され、目的地が他のゲームオブジェクトの1つに設定されます。

最初のものはうまくいきますが、spawnerキュー内の他の17個のNavMeshObjectのいずれも宛先を設定できません。

public class MinionSpawner : MonoBehaviour { 
    public void spawn (GameObject minion, GameObject target_position_obj) { 
     // Find the target position from the passed gameobject 
     MinionTargetPosition target_position = target_position_obj.GetComponent<MinionTargetPosition>(); 
     if (!target_position) { throw new System.Exception("no valid target position given"); } 
     // Instantiate the given minion at the spawner's origin point 
     GameObject new_minion = Object.Instantiate(minion, transform.position, new Quaternion(0,0,0,0)); 
     new_minion.SetActive(true); 
     // Mark the minion at it's target position, for lookup upon collision or elsewhere 
     MinionAttributes minion_attrs = new_minion.GetComponentInChildren<MinionAttributes>(true); 
     if (!minion_attrs) { throw new System.Exception("object passed as minion does not have MinionAttributes"); } 
     minion_attrs.target_position = target_position; 
     // Configure a NavMeshAgent to navigate the minion from origin to target position. 
     NavMeshAgent nav_mesh_agent = minion_attrs.gameObject.GetComponent<NavMeshAgent>(); 
     if (!nav_mesh_agent) { throw new System.Exception("minion doesn't have a nav mesh agent"); }; 
     nav_mesh_agent.Warp(transform.position); 
     // ================================================================ 
     // THIS LINE FAILS: 
     nav_mesh_agent.destination = target_position.transform.position; 
     // ================================================================ 
     // mark the minion's position as occupied in the turret's dictionary 
     Turret turret = target_position.turret; 
     turret.minion_slots[target_position] = true; 
     // set the minion's parent to the minion spawner, for organization's sake. 
     minion.transform.parent = transform; 
    } 
} 

私はエラー"SetDestination" can only be called on an active agent that has been placed on a NavMesh.を取得しており、これについて質問があります。しかし、NavMeshのベーキング、WarpのNavMeshAgentの初期位置の設定、ポイントがメッシュ上にあることを確認することなど、私が実際に提案したすべてを試しました。

答えて

0

問題は、NavMeshagentとは無関係でした。これは、この行だった:

minion.transform.parent = transform; 

私はそれを変更するために必要な:基本的にminionをクローニングしnew_minionがクローンである取得したオブジェクトである

new_minion.transform.parent = transform; 

。ですから、もし私がminionの親を設定したら、将来のクローンのためにそれを台無しにしていると思います。

関連する問題