原本想使用插件來做有决,奈何囊中羞澀埂软,只能自己寫了剩失。通過Value值修改高度缤谎。效果圖:
代碼:
using UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections;
public class cube : MonoBehaviour
{
private Vector3[] vertices;
private Mesh mesh;
[Range(0, 10)]
public float value = 1;//設(shè)置高度值
// Use this for initialization
void Start()
{
vertices = GetComponent<MeshFilter>().mesh.vertices;//獲取Gameobject meshfilter組件
mesh = GetComponent<MeshFilter>().mesh;//獲取meshfilter組件中mesh數(shù)組數(shù)據(jù)
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < vertices.Length; i++)//遍歷數(shù)組
{
if (vertices[i].y >= 0f)//判斷mesh是否為頂部
{
vertices[i].y = value;//設(shè)置mesh頂部高度等于高度值
}
}
mesh.vertices = vertices;//刷新
}
}