Skip to content
Wyatt Hepler edited this page Feb 7, 2015 · 10 revisions

Unity Engine

We will be using the Unity game engine for this game. These are initial proposals about how things will work in Unity. These were chosen after some experimentation but are not necessarily final.

Sprites

2D game objects will be represented using Unity sprites.

Layers

The order in which sprites are rendered is determined by the sprites' sorting layer and sorting order within the layer.

In order from back to front, the following layers will be used:

  1. Background: images always behind the player

  2. Character: images that can be in front of or behind the character and the character itself

  3. Foreground: images always in front of the player

Additional foreground or background layers can be added as needed. There will only be one character layer.

The Character layer

We may want the character to be able to walk in front of and behind the same sprite. For example, the character should render on top of a building when he is in front of it and behind it when he is behind. This can be accomplished with a script that dynamically changes the non-character sprite's sorting order within the Character layer.

The player character will always have a sorting order of 1000. Other objects can have orders 0–999. A script adds or subtracts 1000 to the other sprites' sorting orders based on their position in the y-axis relative to the player.

Camera

The camera will be oriented along the Z axis. An isometric.

Persistence of objects

In-game persistence

Singleton objects should be used for global objects (game state, inventory, player info, etc). If the object is a Unity GameObject (inherits from MonoBehavior), the call DontDestroyOnLoad(Instance) is necessary, otherwise the object will be deleted when scenes change.

Non-Unity objects created like this will persist between scenes:

public class GameState {
	private GameState() {}

	private static GameState instance = null;

	public static GameState Instance {
		get {
			if (instance == null) {
				instance = new GameState();
			}
			return instance;
		}
	}
}

Unity GameObject singletons should be created like this:

public class GameState : MonoBehaviour {
	private GameState() {}

	private static GameState instance = null;

	public static GameState Instance {
		get {
			if (instance == null) {
				instance = new GameObject("GameState").AddComponent<GameState>();
				DontDestroyOnLoad(Instance);
			}
			return instance;
		}
	}
}

Clone this wiki locally