我是Unity的初學者,我想單獨創建一個個人項目。 我在場景上有兩個GameObject,我在Unity上使用LineRenderer和NavMesh代理來繪製兩個gameobjects之間的路徑,到目前爲止,一切都很好,Unity在兩個Gameobjects之間繪製路徑。沿着或穿過路徑放置並複製Gameobject Unity
Void Update(){
OnDrawGiz(GameObject.Find("Destination"));
}
void OnDrawGiz(GameObject obj)
{
Transform target = obj.GetComponent<Transform>();
NavMeshAgent nav;
LineRenderer line;
nav= this.GetComponent<NavMeshAgent>();
if(nav == null || nav.path == null)
return;
line = this.GetComponent<LineRenderer>();
line.material = new Material(Shader.Find("Sprites/Default")) { color
= Color.yellow };
line.startColor=Color.yellow;
line.endColor = Color.green;
nav.SetDestination (target.position);
nav.isStopped=true;
var path = nav.path;
if (path.corners.Length < 2)
return ;
line.positionCount=path.corners.Length ;
//Draw the line
for(int i = 0; i < path.corners.Length; i++)
{
line.SetPosition(i, path.corners[i]);
}
}
darw path 現在我的問題是,我該怎麼和複製遊戲物體,例如立方體沿道路或橫跨這條道路嗎? Here photo the result which i want to have
我使用C#腳本,統一5.6
感謝何塞普·瓦爾斯,它工作得很好:) – mkab
我找到了另一種解決辦法太HTTP:/ /answers.unity3d.com/questions/1365065/put-instantiate-gameobject-along-or-accross-a-path.html?sort=votes – mkab