using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeshTest : MonoBehaviour {
public MeshFilter myMeshFilter;//声明一个网格适配器
public Mesh myMesh; //声明一个网格
public Vector3[] myVertices = new Vector3[4];//声明一组顶点
public int[] myTriangles = new int[6];//声明一组顶点序列
// Use this for initialization
// 当播放时第一帧开始执行
void Start () {
myMesh = new Mesh ();//在内存开辟一个Mesh类型的空间
myMesh.vertices = myVertices;//为myMesh赋予顶点数据
myMesh.triangles = myTriangles;//为myMesh赋予顶点序列数据
myMeshFilter = this.gameObject.AddComponent ();//添加并获取网格适配器组件
myMeshFilter.mesh = myMesh;//为网格适合器组件的mesh属性赋值
this.gameObject.AddComponent ();//添加网格渲染组件
}
// Update is called once per frame
void Update () {
}
}
using System.Collections.Generic;
using UnityEngine;
public class MeshTest : MonoBehaviour {
public MeshFilter myMeshFilter;//声明一个网格适配器
public Mesh myMesh; //声明一个网格
public Material myMaterial;
public Vector3[] myVertices = new Vector3[4];//声明一组顶点
public int[] myTriangles = new int[6];//声明一组顶点序列
/*
// Use this for initialization
// 当播放时第一帧开始执行
void Start () {
myMesh = new Mesh ();//在内存开辟一个Mesh类型的空间
myMesh.vertices = myVertices;//为myMesh赋予顶点数据
myMesh.triangles = myTriangles;//为myMesh赋予顶点序列数据
myMeshFilter = this.gameObject.AddComponent ();//添加并获取网格适配器组件
myMeshFilter.mesh = myMesh;//为网格适合器组件的mesh属性赋值
this.gameObject.AddComponent ();//添加网格渲染组件
}
*/
void Start(){
myMesh = new Mesh ();//在内存开辟一个Mesh类型的空间
myMesh.vertices = myVertices;//为myMesh赋予顶点数据
myMesh.triangles = myTriangles;//为myMesh赋予顶点序列数据
MeshFilter myMeshFilter = this.gameObject.GetComponent();//获取脚本所在物体的网格适配器
myMeshFilter.mesh = myMesh;//为网格适配器赋值
MeshRenderer myMeshRenderer = this.gameObject.GetComponent ();//获取脚本所在物体的网格渲染器
myMeshRenderer.material = myMaterial;//为网格渲染赋值
myMesh.RecalculateNormals();
// this.transform.position = Vector3.up * 5;
// this.gameObject.GetComponent ().position = Vector3.up * 5;
}
// Update is called once per frame
void Update () {
}
}
只有一个面 只有一个面
网友评论