나는 많은 수의 비행 물체를 가지고 있는데, 나는 그들에게 약간의 경유지를 줄 필요가있다. 내가 원하는 것은 자유로운 스타일로 지형 지역을 날아 다니는 것입니다.지형 영역의 중간 점 배열을 만들려면 어떻게해야합니까?
웨이 포인트로 할 수 있습니까?
Main.cs 스크립트의 주 카메라 속성에있는 스크린 샷에서 인스턴스 포인트가 있습니다. 크기는 요소 0으로 1입니다. 요소는 InstancePoint 계층에 있습니다. InstancePoint에서 웨이 포인트를 얻는 스크립트 추적이 있습니다.
이 웨이 포인트는 물체가 지나가는 곳입니다. 이제 웨이 포인트 크기는 0입니다. 객체가 지형 영역 주위를 돌아 다니며 자유 스타일과 3-4 웨이 포인트 사이를 돌아 다니는 지형 영역이 될 웨이 포인트로 일부 GameObject를 만들 수 있는지 궁금합니다. 아니면 논리가 전혀 다른 점이 있습니다.
이
는 추적 스크립트입니다using System;
using UnityEngine;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
public class Trace: MonoBehaviour
{
public Material normalState;
public Material activeState;
public WayPoint[] wayPoints;
private WayPoint curWP = null;
public void Start()
{
foreach(var wp in wayPoints)
SetTrigger(wp, false);
if(wayPoints.Length > 0)
{
curWP = wayPoints[0];
SetTrigger(curWP, true);
}
}
void SetTrigger(WayPoint wp, bool value)
{
wp.GetComponent<Collider>().isTrigger = value;
wp.GetComponent<Renderer>().material = value ? activeState : normalState;
}
#if UNITY_EDITOR
[UnityEditor.MenuItem ("GameEditor/Collect route from priority of waypoints")]
static void DoSomething()
{
Trace curTrace = (Trace)FindObjectOfType(typeof(Trace));
var list = new List<WayPoint>();
var rgx = new Regex(@"\d+$");
//Selection.gameObjects doesn't hold selection order
foreach(var obj in FindObjectsOfType(typeof(WayPoint)))
{
var wp = (WayPoint)obj;
list.Add(wp);
wp.name = rgx.Split(obj.name)[0] + wp.editorPriority.ToString("D2");
wp.trace = curTrace;
}
list.Sort((t1, t2) => t1.editorPriority - t2.editorPriority);
//ths.wayPoints = list.Select((v) => v.gameObject).ToArray();
curTrace.wayPoints = list.ToArray();
}
#endif
public Vector3 GetAtractionPoint()
{
return curWP.transform.position;
}
public void NextWayPoint()
{
SetTrigger(curWP, false);
var nextIndex = Array.FindIndex(wayPoints, (v) => v == curWP) + 1;
if(nextIndex == wayPoints.Length)
nextIndex = 0;
curWP = wayPoints[nextIndex];
SetTrigger(curWP, true);
}
}