2016-10-02 2 views
-2

나는 많은 수의 비행 물체를 가지고 있는데, 나는 그들에게 약간의 경유지를 줄 필요가있다. 내가 원하는 것은 자유로운 스타일로 지형 지역을 날아 다니는 것입니다.지형 영역의 중간 점 배열을 만들려면 어떻게해야합니까?

웨이 포인트로 할 수 있습니까?

Main.cs 스크립트의 주 카메라 속성에있는 스크린 샷에서 인스턴스 포인트가 있습니다. 크기는 요소 0으로 1입니다. 요소는 InstancePoint 계층에 있습니다. InstancePoint에서 웨이 포인트를 얻는 스크립트 추적이 있습니다.

이 웨이 포인트는 물체가 지나가는 곳입니다. 이제 웨이 포인트 크기는 0입니다. 객체가 지형 영역 주위를 돌아 다니며 자유 스타일과 3-4 웨이 포인트 사이를 돌아 다니는 지형 영역이 될 웨이 포인트로 일부 GameObject를 만들 수 있는지 궁금합니다. 아니면 논리가 전혀 다른 점이 있습니다.

Screenshot

는 추적 스크립트입니다

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

답변

0

오히려 유니티와 함께 ​​제공되는 애니메이터를 사용하는 것이 훨씬 쉬울 것 스크립트를 이런 식으로 행동하는 당신의 비행 물체를 취득하는 것보다.

키 프레임을 사용하여 다른 위치 (경유 점)를 선택하고 기본 제공 도구를 사용하여 부드러운 애니메이션 커브를 만들 수 있습니다. 그런 다음이 동작을 변경하려면 스크립트를 사용하여보다 적절한 애니메이션으로 전환하십시오.

소개 주제 비디오>Animation in Unity

관련 문제