Chapter 5. Building a Memory game using Unity’s new 2D functionality
This chapter covers
- Displaying 2D graphics in Unity
- Making objects clickable
- Loading new images programmatically
- Maintaining and displaying state using UI text
- Loading levels and restarting the game
Up to now we’ve been working with 3D graphics. But you can also work with 2D graphics in Unity, so in this chapter you’ll build a 2D game to learn about that. We’re going to develop the classic children’s game Memory: we’ll display a grid of card backs, reveal the card front when it’s clicked, and score matches. These mechanics cover the basics you need to know in order to develop 2D games in Unity.
Although Unity originated as a tool for 3D games, it’s used often for 2D games as well. Recent versions of Unity (starting with version 4.3, released near the end of 2013) have added the ability to display 2D graphics, but even before then 2D games were already being developed in Unity (especially mobile games that took advantage of Unity’s cross-platform nature). In prior versions of Unity, game developers required a third-party framework (such as 2D Toolkit from Unikron Software) to emulate 2D graphics within Unity’s 3D scenes. Eventually the core editor and game engine were modified to incorporate 2D graphics, and this chapter will teach you about that newer functionality.