First foray into Unity

I haven’t posted here in a while because I’ve been lazy and there hasn’t really been enough happening to warrant a full post. A quick recap.


A few weeks ago I entered js13kGames with TSVETT, a color matching game. It got 8th place in the Mobile category. I’ve written an article about the color matching aspect of the game (including some information about color difference values and formulae) for HTML5Hub. You can read it here.


I have also begun to experiment with other engines. I recently learned about Goo Engine, a webGL and HTML5 based engine for creating 3D browser games. It’s extremely interesting, but as someone who has only ever worked on 2D projects in my spare time I was completely lost when starting out. The documentation is great, but 3D concepts in general proved to be elusive to my 2D-centric brain. So I set out on a mission to learn more about 3D graphics. I even started a Tumblr to post 3D progress (it seems better suited for quick image posts than this blog, which I reserve for longer material). I called it Which Way Up (stemming from a Twitter comment I made not long before about not even knowing which way is up anymore while experimenting with Goo).

This eventually led me back to Unity3D.

Unity so far

So here’s where we are with my October One Game a Month project. I kind of just threw things together until they worked and have decided to stay away from Unity’s “JavaScript” to spend more time with C#, so prepare for chaos (and as usual sorry about the weird way my code pasting Wordpress plugin screws the indentation sometimes).

I made a dodecahedron in Blender.

[caption id=“attachment_49540” align=“aligncenter” width=“276”] Dodecahedron Dodecahedron[/caption]

It moves.

if (IsGrounded()) {
            if (gameStarted && scoringScript.currentScore == 0 && !isMoving) {
            if (Input.GetButton("Jump")) {
                moveDirection.y = jumpSpeed;

        else {
            if (gameStarted && scoringScript.currentScore != 0) {
                scoringScript.currentScore = 0;
            rotationDirection = new Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
            rotationDirection *= speed;
            rigidbody.AddTorque(rotationDirection * Time.deltaTime);
        moveDirection.y -= gravity * Time.deltaTime;
        rigidbody.AddForce(moveDirection * Time.deltaTime);

When a session starts, x characters are picked from a character pool at random. They are the adventurers you’ll be trying to keep alive during that session.

    void Start () {
        character[] characterArr = SetCharacterData();

        // Pick characters for session at random
        int quantity = 2;
        int i = 0;
        int x = -70;
        int y = -35;
        while (i < quantity) {
            character character = PickCharacter(characterArr);
            GameObject characterObject = GameObject.Find ("Character" + (i + 1));

            GUIText guiTextComponent = characterObject.GetComponent<GUIText>();
            guiTextComponent.text = character.Name;

            GUITexture guiTexture = characterObject.GetComponent<GUITexture>();
            guiTexture.texture = Resources.Load (character.Avatar) as Texture2D;
            guiTexture.pixelInset = new Rect(x, y, 70, 70);

            State state = characterObject.GetComponent<State>();
            state.alive = true;
            state.goodLines = character.Goodlines;
            state.badLines = character.Badlines;
   = character.Name;


It picks a target side to make green.

        Material material = new Material(Shader.Find("Custom/VertexColor"));

        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;
        Color[] colors = new Color[vertices.Length];

        int i = 0;
        while (i < vertices.Length) {
            if (i < targetFace * 5 && i >= targetFace * 5 - 5) {
                colors[i] =;
            else {
                colors[i] =;
        mesh.colors = colors;
        renderer.material = material;

It selects which of your brave adventurers is rolling this turn:

        GameObject character = allCharacters[Random.Range(1, allCharacters.Length)].gameObject;
        bool isAlive = character.GetComponent<State>().alive;
        if (!isAlive) {
            return PickCharacter();
        character.GetComponent<GUIText>().text = character.GetComponent<GUIText>().text + " (Now Rolling!)";
        return character.gameObject;

It checks if you’ve landed with the target side up

        Vector3 vertex1 = GetComponent<MeshCollider>().transform.TransformPoint(targetVertex1);
        Vector3 vertex2 = GetComponent<MeshCollider>().transform.TransformPoint(targetVertex2);
        Vector3 vertex3 = GetComponent<MeshCollider>().transform.TransformPoint(targetVertex3);

        float distanceFromGround1 = Mathf.Abs (vertex1.y - table.y); 
        float distanceFromGround2 = Mathf.Abs (vertex2.y - table.y);
        float distanceFromGround3 = Mathf.Abs (vertex3.y - table.y);
        float diffInDistance = Mathf.Abs (distanceFromGround1 - distanceFromGround2) - Mathf.Abs (distanceFromGround1 - distanceFromGround3);
        if (distanceFromGround1 > 3.6 && diffInDistance < 0.18) {
            currentScore = 1;
        else {
            currentScore = -1;
        CharacterEvent characterEvent = adventurerController.GetComponent<CharacterEvent>();

When you don’t land your die with the target side up, bad things happen. People die. David is writing the event lines and attempting to make me go out of scope with the entire idea at the same time. Because hey, it’s not like I need to finish this by the end of October so yeah, let’s put in XP and character abilities and stuff.

Farmer Line

The game ends when all of your adventurers have perished.

© - 2021 · Liza Shulyayeva ·