Match 3: Starting with the GUI in Unity

Today's time on the project was marked/marred by things that perhaps should've been obvious. I've discovered that, while a lot of the scripting is pretty easy and the UI makes a lot of otherwise very complex things somewhere between easy and hilariously trivial, there are some very important basics that I clearly don't get the way I need to. Primarily: 2D coordinates. Which feels a little pathetic.

On the plus side, I managed to work around that, and there's a pretty, pretty picture to prove it!

...unfortunately, it's utter crap. Sorry, that would be my first attempt at capturing frames from a running Unity project at a frame rate appropriate for an animated GIF. It clearly did not work well. This actually looks pretty freaking slick.

But there's at least a few important things that have been finished.

  • Tiles are being created programmatically from Unity prefabs.
  • Their animations and animation transitions work.
  • The whole thing starts rather orderly but gets wonderfully chaotic very quickly.
  • Pretty colors; pretty random.

The sprites come from Oryx' Sci-Fi sprite pack, which is awesome, but I think I've pretty much spammed Oryx links enough from my posts (despite no affiliate linking, wink wink, nudge nudge). Plus, it googles well, so if you're interested, by all means check it out.

I'd like to use the UI elements from that as well, but that part has been... slightly trickier. Part of it is, as you may be able to see from the GIF, the import is crap. Which seems to be due to a combination of me not having the right import settings and me not having the right camera/canvas/whatever settings. So largely a whole lot of me not knowing what the hell I'm doing.

This is unlikely to be interesting to anyone, but just in case, this is my newbish approach to building the little tech demo presented in the gif above.

using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {
	public GameObject[] cubes;

	void SpawnRandomCube(Vector3 position) {
		GameObject cube;

		cube = (GameObject)Instantiate (cubes[Random.Range(0, cubes.Length)]);
		cube.transform.position = position;
		StartCoroutine(Respawn (cube));

	IEnumerator Respawn(GameObject cube) {
		yield return new WaitForSeconds (Random.Range (1, 10));

		Animator animator = cube.GetComponent ();
		animator.SetTrigger ("CubePop");

		yield return new WaitForSeconds (0.5f);

		yield return new WaitForSeconds (0.3f);

		SpawnRandomCube (cube.transform.position);
		Destroy (cube);

	void Start () {
		for (float x = -0.8f; x <= 0.8f; x += 0.25f) {
			for (float y = -0.75f; y <= 0.85f; y += 0.25f) {
				SpawnRandomCube (new Vector3 (x, y, 0f));

MonoDevelop uses hard tabs. God, I have so much to teach it.


Comments powered by Disqus

Contents © 2016 internationalfish