使用Gizmos的DrawLine方法画线。
首先在场景中找到五角星的五个定点的坐标,按照一笔画的顺序命名为1,2,3,4,5,如图所示:
接下来就是编写代码了,代码很少,如下所示:
using UnityEngine;
using System.Collections; public class fiveStars : MonoBehaviour { public Transform[] fivePoints = new Transform[5];
// Use this for initialization
void Start () {
} // Update is called once per frame
void Update () { } void OnDrawGizmos()
{
Gizmos.color = Color.red;
for (int i = 1; i < fivePoints.Length; i++)
{
Gizmos.DrawLine(fivePoints[i-1].position, fivePoints[i].position);
}
Gizmos.DrawLine(fivePoints[4].position, fivePoints[0].position);
}
}
最后的效果图如下所示: