加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

unity绘制cube的方式

(2019-09-05 10:38:23)
标签:

unity

分类: 我的学习生活
https://docs.unity3d.com/ScriptReference/PrimitiveType.Cube.html

using UnityEngine;
using System.Collections;

// Creates a cube primitive

public class ExampleClass : MonoBehaviour { void Start() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); } }


https://blog.csdn.net/nanggong/article/details/54314699


using UnityEngine;

using System.Collections;

 

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]

public class Test3D : MonoBehaviour

{

 

    public Material mat;

 

 

 

    // Use this for initialization

    void Start()

    {

 

        DrawCube();

 

    }

 

    #region 画正方体

    void DrawCube()

    {

        gameObject.GetComponent().material = mat;

 

        Mesh mesh = GetComponent().mesh;

        mesh.Clear();

 

        //设置顶点

        mesh.vertices = new Vector3[]

         new Vector3(0, 0, 0),

            new Vector3(1, 0, 0),

            new Vector3(1, 1, 0),

            new Vector3(0, 1, 0),

            new Vector3(0, 1, 1),

            new Vector3(1, 1, 1),

            new Vector3(1, 0, 1),

            new Vector3(0, 0, 1),

        };

        //设置三角形顶点顺序,顺时针设置

        mesh.triangles = new int[]

        {

          0, 2, 1,

            0,3,2,

            3,4,2,

            4,5,2,

            4,7,5,

            7,6,5,

            7,0,1,

            6,7,1,

            4,3,0,

            4,0,7,

            2,5,6,

            2,6,1

 

        };

    }

    #endregion

 

}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有