Unity学习笔记–画个平面五角星
用Gizmos画一个简单的五角星,然后就开始学GL啦。
- 效果如下:
- 五个坐标点为:
- 新建一个Scripts打开后编写代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Painting : MonoBehaviour {
public Transform[] fivePoints = new Transform[5];
void Start () {}
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);
}
}
- 在unity下新建5个空物体,命名1,2,3,4,5,并按上面的坐标以此设置位置。
- 新建一个空物体用来加载我们写的代码。并将上面的1-5个点放置进去。
此时左侧窗口便完成了图形的绘制。