簡體   English   中英

Unity-翻譯GameObject 3d Cube Edge

[英]Unity - Translate a GameObject 3d Cube Edge

我使用C#腳本用幾個多維數據集填充場景,然后選擇一定數量的多維數據集並對其進行轉換。 我想做的變換是根據這張圖片

如何移動基本Unity 3d對象立方體的邊緣(在C#腳本中)?

您可以通過編輯網格的頂點來實現。 例如,將此腳本附加到多維數據集並調整相機,以便您在按空格鍵時可以看到事物在四處移動。 您應該會看到方框的變化,並了解如何獲得所需的東西。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM