First Cube

By Plump Helmet Studios on

First Cube

And so, with the end of the second day in operation, Plump Helmet Studios produces it's first cube. The beginnings are humble, the achievements small, but every great journey begins with a simple step.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class Cube : MonoBehaviour
{
    Mesh mesh;
    Vector3[] vertices;
    int[] triangles;

    void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        vertices = new Vector3[] {
            new Vector3(0, 0, 0), // front bottom left
            new Vector3(1, 0, 0), // front bottom right
            new Vector3(1, 1, 0), // front top right
            new Vector3(0, 1, 0), // front top left
            new Vector3(0, 1, 1), // back top left
            new Vector3(1, 1, 1), // back top right
            new Vector3(1, 0, 1), // back bottom right
            new Vector3(0, 0, 1)  // back bottom left
        };
        triangles = new int[] {
            0, 2, 1, // front
            0, 3, 2,
            0, 7, 4, // left
            0, 4, 3,
            5, 4, 7, // back
            5, 7, 6,
            1, 2, 5, // right
            1, 5, 6,
            2, 3, 4, // top
            2, 4, 5,
            0, 6, 7, // bottom
            0, 1, 6
        };
    }

    void Start()
    {
        mesh.Clear();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }
}