[英]Unity - Translate a GameObject 3d Cube Edge
您可以通过编辑网格的顶点来实现。 例如,将此脚本附加到多维数据集并调整相机,以便您在按空格键时可以看到事物在四处移动。 您应该会看到方框的变化,并了解如何获得所需的东西。
public class CubeScript : MonoBehaviour {
int vert_num = 0;
Mesh mesh;
Vector3[] verts;
// Use this for initialization
void Start () {
mesh = GetComponent<MeshFilter>().mesh;
verts = mesh.vertices;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Space)) {
// Loop back around after the last vert
if (vert_num >= verts.Length) {
vert_num = 0;
}
// Move the next vert and echo its number
Debug.Log("Moving vert#: " + vert_num);
verts[vert_num] += Vector3.up * 0.1f;
mesh.vertices = verts;
vert_num += 1;
}
}
}
有关更多信息,请参见: https : //docs.unity3d.com/ScriptReference/Mesh.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.