Designing a Simple Level in Unity with ProBuilder

Getting Started with ProBuilder

To begin, create a new Unity 3D project and name it “Hello ProBuilder.” If you haven’t already, download and install the ProBuilder package from the Unity Asset Store.

Setting up ProBuilder

Once installed, open the ProBuilder window by clicking on “Tools” > “ProBuilder” > “ProBuilder Window.” Dock the window wherever you prefer, such as next to the Hierarchy panel.

Creating a Room with ProBuilder

Let’s start by creating a simple room. Click on “New Shape” and select the cube icon. Hold left-click and drag the shape out to create a cube with dimensions 5 x 2 x 5. Make sure you’re in Object selection mode and select the cube. Click “Flip Normals” from the ProBuilder panel to create a room.

// Example code to create a cube
using UnityEngine;
using ProBuilder;

public class CreateCube : MonoBehaviour
{
    void Start()
    {
        // Create a new ProBuilder mesh
        Mesh mesh = new Mesh();

        // Define the vertices, edges, and faces of the cube
        Vector3[] vertices = new Vector3[8] {
            new Vector3(-0.5f, -0.5f, -0.5f),
            new Vector3(0.5f, -0.5f, -0.5f),
            new Vector3(0.5f, 0.5f, -0.5f),
            new Vector3(-0.5f, 0.5f, -0.5f),
            new Vector3(-0.5f, -0.5f, 0.5f),
            new Vector3(0.5f, -0.5f, 0.5f),
            new Vector3(0.5f, 0.5f, 0.5f),
            new Vector3(-0.5f, 0.5f, 0.5f)
        };

        int[] edges = new int[12] {
            0, 1,
            1, 2,
            2, 3,
            3, 0,
            4, 5,
            5, 6,
            6, 7,
            7, 4
        };

        int[] faces = new int[6] {
            0, 1, 2, 3,
            4, 5, 6, 7,
            0, 1, 5, 4,
            1, 2, 6, 5,
            2, 3, 7, 6,
            3, 0, 4, 7
        };

        // Assign the vertices, edges, and faces to the mesh
        mesh.vertices = vertices;
        mesh.edges = edges;
        mesh.faces = faces;

        // Flip the normals of the mesh
        mesh.FlipNormals();
    }
}

Adding Stairs

Next, let’s add stairs to our room. Scale the room up 10x by selecting the cube and adjusting the scale property in the Inspector panel. Switch to the ProBuilder panel and click “New Shape,” then select the stairs icon. Left-click and hold to stretch the stairs along the X and Z axes. Release left-click and move the cursor along the +ve Y axis to set the height of the stair.

Refining the Stairs

Experiment with different stair settings, such as changing the number of steps or the step height. You can also adjust the shape properties, such as the width and depth of the stairs.

Adding a Platform

Let’s add a platform at the end of the stairs. Switch to Face Selection mode and select the end face of the stairs. Hold Shift and drag the selected face forward to extrude it. Increase the length of the platform horizontally and adjust its thickness as needed.

Beveling Edges

Finally, let’s bevel the edges of the platform. Select the face or edge you want to bevel and click the Bevel button from the ProBuilder panel. Adjust the amount of beveling to your liking.

Bringing a Character into Your Environment

Download the free Starter Assets pack from Unity and import it into your project. Delete the Main Camera from the scene and drag the NestedParentArmature_Unpack prefab into the scene. Position it inside the room and adjust its scale as needed.

Final Touches

Click Play to test your level and make any necessary adjustments. Use the W, A, S, and D keys to move around, hit Space to jump, and use the mouse to look around.

Leave a Reply

Your email address will not be published. Required fields are marked *