Esempio n. 1
0
    //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;

            }
        }
    }
Esempio n. 2
0
    //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.
            }
        }
    }