📜  unity create cube in script - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:19.185000             🧑  作者: Mango

代码示例1
void Start()
    {
        /*GameObject != gameObject*/
        GameObject cubeObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
        
        /*if you need add position, scale and color to the cube*/
        cubeObject.transform.localPosition = new Vector3(0, 1, 0);
        cubeObject.transform.localScale = new Vector3(1, 1, 1);
        cubeObject.GetComponent().material.color = Color.red  ;
    }