Unity学习笔记--画个平面五角星

Unity学习笔记–画个平面五角星
用Gizmos画一个简单的五角星,然后就开始学GL啦。

  1. 效果如下:
    在这里插入图片描述
  2. 五个坐标点为:
    在这里插入图片描述
  3. 新建一个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);
    }
  }
  1. 在unity下新建5个空物体,命名1,2,3,4,5,并按上面的坐标以此设置位置。
  2. 新建一个空物体用来加载我们写的代码。并将上面的1-5个点放置进去。
    在这里插入图片描述
    此时左侧窗口便完成了图形的绘制。

猜你喜欢

转载自blog.csdn.net/qq_42434073/article/details/107562221
今日推荐