2016-10-02 20 views
-2

我有一些飞行物体,我需要给他们一些航点。 我想要的是让他们以自由的风格飞越地形区域。如何创建地形区域的航点数组?

它是否在与航点做呢?

在Main.cs脚本的主摄像头检查器上的屏幕截图中,我有实例点大小为1,元素为0.元素在层次结构InstancePoint上。在InstancePoint中,我拥有获取Way Points的脚本Trace。

在这种方式下物体应该在两者之间飞行。现在路点大小为0,我想知道是否有可能创建一些GameObjects作为将成为地形区域的航点,以便对象将围绕地形区域飞行,但是自由风格,而不仅仅是3-4个航点之间?或者,也许逻辑应该是没有任何方法点的东西?

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

相关问题