原本想使用插件来做,奈何囊中羞涩,只能自己写了。通过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;//设置高度值
// Use this for initialization
void Start()
{
vertices = GetComponent<MeshFilter>().mesh.vertices;//获取Gameobject meshfilter组件
mesh = GetComponent<MeshFilter>().mesh;//获取meshfilter组件中mesh数组数据
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < vertices.Length; i++)//遍历数组
{
if (vertices[i].y >= 0f)//判断mesh是否为顶部
{
vertices[i].y = value;//设置mesh顶部高度等于高度值
}
}
mesh.vertices = vertices;//刷新
}
}