当前位置: 首页>>代码示例>>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;未经允许,请勿转载。