當前位置: 首頁>>代碼示例>>C#>>正文


C# Rigidbody.AddComponent方法代碼示例

本文整理匯總了C#中UnityEngine.Rigidbody.AddComponent方法的典型用法代碼示例。如果您正苦於以下問題:C# Rigidbody.AddComponent方法的具體用法?C# Rigidbody.AddComponent怎麽用?C# Rigidbody.AddComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Rigidbody的用法示例。


在下文中一共展示了Rigidbody.AddComponent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Start

    //Vector3 posChange = new Vector3(2, 2, 0);
    // Use this for initialization
    void Start()
    {
        //Creates the cube GameObject
        GameObject cube = new GameObject();

        //Works through creating the 8x8 wall of cubes
        for (int x = 0; x < 8; x++)
        {
            for (int y = 0; y < 8; y++)
            {

                // The position I want the wall to start at (close to player)
                float posX = 429.89f;
                float posY = 0.528f;
                float posZ = 229.5f;

                //Moves the position of each box as the for loop goes through it
                Vector3 position = new Vector3(posX + y * cubeW, posY + x * cubeH, posZ);

                //My attempt at instantiation
                //Rigidbody instanstiateCube = Instantiate(cube, transform.position = positionCube, transform.rotation) as Rigidbody;

                //Actual creation of the cube as a cube game object
                cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                //Positions the new cube into the position of the position vector
                cube.transform.position = position;

                //Makes the cubes a rigidbody
                Rigidbody gameObjectsRigidBody = cube.AddComponent<Rigidbody>();
                //Changes the mass of the cubes
                gameObjectsRigidBody.mass = 0.5f;

            }
        }
    }
開發者ID:vv1n5t0n,項目名稱:FirstAssignment,代碼行數:37,代碼來源:FirstScript.cs

示例2: Start

    //Vector3 posChange = new Vector3(2, 2, 0);
    // Use this for initialization
    void Start()
    {
        GameObject cube = new GameObject();

        for (int x = 0; x < 9; x++)
        {
            for (int y = 0; y < 9; y++)
            {
                float posX = 430.0f;
                float posY = 0.528f;
                float posZ = 220.0f;

                Vector3 position_ = new Vector3(posX + y * cubeW, posY + x * cubeH, posZ);

                //Rigidbody instanstiateCube = Instantiate(cube, transform.position = positionCube, transform.rotation) as Rigidbody;

                cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.position = position_;

                Rigidbody gameObjectsRigidBody = cube.AddComponent<Rigidbody>(); // Add the rigidbody.
                gameObjectsRigidBody.mass = 0.5f;//Set the GO's mass to 1 via the Rigidbody.
            }
        }
    }
開發者ID:Nerugui,項目名稱:First-Assignment,代碼行數:26,代碼來源:FirstScript.cs


注:本文中的UnityEngine.Rigidbody.AddComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。