Set up your 2D game world

Tutorial

·

Beginner

·

+10XP

·

20 mins

·

(316)

Unity Technologies

Set up your 2D game world

In this tutorial, you'll preview the finished version of Sprite Flight: a simple, 2D arcade game where you steer a triangular ship to dodge flying obstacles. Then, you'll create a new Unity project using Unity’s 2D template and set up the basic play area for your 2D game, complete with walls around the edges of the screen.

Languages available:

1. Overview

Let’s start by previewing the game you're going to build. In Sprite Flight, you control a triangular ship that flies around a rectangular game space. The goal is to survive for as long as possible by avoiding the moving obstacles. The longer you stay alive, the higher your score climbs. If your ship collides with an obstacle or wall, it explodes — and it’s game over.


By the end of this course, you'll have created your own version of this game from scratch. Along the way, you’ll learn how to do the following:


  • Set up and navigate Unity’s 2D environment

  • Use physics components to simulate bouncing and movement

  • Write simple C# scripts and attach them to GameObjects

  • Build and display a live scoring system

  • Handle collisions, UI, and game restart logic

Previewing the final game helps you understand where you’re headed and why each step along the way matters.



1. Play the web version of the demo game:



  • Click or tap anywhere to steer the ship in that direction.

  • Your score increases the longer you stay alive.

  • Avoid the flying hexagons and the outer walls.


2. Observe how the game is built:


  • Notice the basic shapes: a triangular player, square borders, and hexagon obstacles.

  • Pay attention to how the movement feels — there's momentum, bounce, and randomness.

You’ve now experienced the final version of Sprite Flight and have a clear goal in mind. Next, you’ll start your own project and begin building the game world step-by-step.


2. Create a new 2D project

Now that you’ve previewed the final game, it’s time to start building it yourself. In this step, you’ll create a new Unity project using the Universal 2D template. This template sets up your environment with settings and tools suited for 2D games.



1. Launch Unity Hub:


  • Open the Unity Hub on your computer.

  • If you don’t have Unity Hub or a version of Unity 6 installed yet, download and install it from unity.com/download.

2. Create a new project:


  • Select the New Project button.

  • Select the Universal 2D template.

  • Name your project “Sprite Flight” or something similar.

  • Set a project location on your computer where you can easily find it.

  • Select Create Project and wait while Unity sets up your files and opens the Editor.

Important: Make sure you select the Universal 2D template or your project won’t be configured properly to create this project.


You now have a fresh Unity project using the Universal 2D template, ready for development.


3. Set up your layout

Unity’s layout is customizable, and organizing your windows early helps you work more efficiently. Also, setting your layout so that it matches the instructions and screenshots in this course will make the tutorials easier to follow.


In this step, you’ll arrange your workspace so that you can see the Scene view, Game view, Hierarchy, Project, and Inspector windows all at once.



1. Select the 2 by 3 layout preset:


  • In the upper-right corner of the Unity Editor, open the Layout dropdown and select 2 by 3.

2. Move the Project window below the Hierarchy window:


  • Drag the Project window so it sits below the Hierarchy window.

  • Drag the upper-edge of the Project window up so that it aligns with the top of the Game view.

3. Tidy the Project window view:


  • In the Project window, select the More () menu and ensure that the One Column layout is enabled.

Your layout is now configured so you can comfortably access all the tools you’ll need during development and more easily follow along with this course.


4. Navigate around a new 2D scene

Creating a new scene ensures a clean, organized starting point for your game. In this step, you’ll set up and save a dedicated scene.



1. Create your new scene:


  • In the Project window, right-click the Scenes folder and select Create > Scene > Scene.

  • Rename the new scene “Game”.

2. Open the Game scene:


  • Double-click the Game scene to open your new scene.

  • A dialog stating “Scene(s) have been modified” might appear, referencing the SampleScene. When prompted, select Don’t Save, as you have created a new scene, and so SampleScene is no longer needed.

  • You’ll now see the name of your scene (Game) appear at the top of the Hierarchy window.

3. Practice navigating in 2D:


  • Use your scroll wheel (or two-finger swipe on a trackpad) to zoom in and out of the Scene view.

  • Ensure the View tool (hand) is selected from the Tools overlay in the Scene view, then hold right-click and drag to pan around the scene.

Tip: Navigating the Scene view with these gestures will help you quickly place and adjust GameObjects throughout this course. To learn more about scene navigation, check out the Explore the Unity Editor tutorial.


You now have a new empty scene open in the Unity Editor and understand how to navigate 2D space.


5. Add an Obstacle sprite

To build your game world, you'll start by adding a simple hexagon-shaped obstacle to your scene. In Unity, 2D objects are made using sprites — flat images that can be moved, colored, and given physical properties. You’ll place a hexagon-shaped sprite at the center of the scene.


Unity uses an (x, y, z) coordinate system. In this system, the x-axis runs left to right, and the y-axis runs up and down. In 2D games, the z-axis is ignored — since it goes forward and back in the scene. The origin — the center of the scene — is located at position (0, 0, 0).



1. Add a 2D hexagon sprite:


  • Right-click in the Hierarchy window and select 2D Object > Sprites > Hexagon Flat Top.

  • This creates a new 2D GameObject in your scene using Unity’s built-in Hexagon shape.

2. Rename and reposition the GameObject:


  • Rename the new GameObject “Obstacle”.

  • In the Inspector window, set its Transform > Position to X=0, Y=0, Z=0.

Note: In 2D, the z-axis value is still required, but it won’t affect rendering or gameplay.


3. Change the color (optional):


  • In the Sprite Renderer component, select the Color swatch.

  • Select a new color from the Color window to help the obstacle stand out visually in the scene.

You've now placed a static obstacle in the world, centered at the origin. You'll later give it physics properties so it can move and bounce — but for now, it's a visual reference point in your 2D space.


6. Change the size and background of the camera

In 2D games, the default camera uses an Orthographic projection, meaning it shows the world without perspective (objects don’t get smaller as they move away). Instead of zooming in or out with the camera, you control how much of the scene is in view by changing the Size property.


Right now, the area in view is a little bit too small. In this step, you'll adjust the orthographic size of the Main Camera to zoom out a bit, and if you want, you can also change the background color.



1. Select the Main Camera:


  • In the Hierarchy window, select the Main Camera GameObject.

  • In the Inspector window, find the Camera component.

2. Adjust the orthographic size:


  • Under the Projection section, make sure the Projection property is set to Orthographic.

  • Increase the Size property to a value around 7.5.

Note: A higher size zooms the camera out, showing more of the scene.


  • Watch the white rectangle in the Scene view expand as you adjust this setting.

3. Change the background to a solid color:


  • Use the foldout (triangle) to expand the Environment section, then change the Background Type property from Skybox to Solid Color.

  • Select the Background swatch and select a background color that complements your obstacle.

Note: A skybox is a 3D environment wrapper used in 3D games. Since you're making a 2D game, a solid background color is simpler and more appropriate.


After this step, your camera shows a larger area of the game world, and the background color is adjusted to your liking.


7. Create the first screen border

Your player and obstacles need to stay within visible bounds, so it's time to build a screen boundary.


You'll create a 2D sprite to act as the bottom wall, and use Unity’s Rect Tool to position and size it. This tool lets you directly manipulate the shape and size of 2D GameObjects in the Scene view.



1. Add a square sprite to act as the bottom border:


  • In the Hierarchy window, right-click and choose 2D Object > Sprites > Square.

  • Rename the new GameObject “Border_Bottom”.

2. Switch to the Rect Tool:


  • With the Border_Bottom GameObject selected, select the Rect tool from the Tool overlay in Scene view.

Tip: You can also press T with your cursor in the Scene view to activate the Rect Tool.


  • You’ll now see handles around the GameObject that let you resize it directly in the Scene view and a circle at the sprite’s center which you can click and drag around.

Note: Depending on how zoomed out your Scene view is, you might need to zoom in to see the handles around the Border_Bottom GameObject.


3. Resize and position the wall:


  • Use the Rect tool to stretch the border horizontally and move it downward to sit at the bottom edge of the camera bounds.

  • You can use the white camera rectangle in the Scene view as a guide.

  • If you can’t see the camera bounds clearly, zoom out with your mouse wheel or right-click and drag to navigate in the Scene view.


After this step, your game now has its first world boundary — a solid wall at the bottom of the screen to stop obstacles and keep the player inside the play area.


8. Duplicate to make other screen borders

With the bottom border in place, you’ll now add the remaining three screen borders: top, left, and right. Rather than creating each from scratch, you’ll duplicate the existing object and reposition it using the Rect Tool.



1. Select and duplicate the bottom border:


  • In the Hierarchy window, select the Border_Bottom GameObject.

  • Press Ctrl+D (macOS: Cmd+D) to duplicate it, then rename the new GameObject to ”Border_Top”.

2. Move and resize the top border:


  • Use the Rect tool (press T if needed) or the Move tool (press W) to move the Border_Top GameObject to the top edge of the camera bounds.

3. Repeat for the left and right borders:


  • Duplicate the Border_Bottom GameObject again to create Border_Left, then position and resize it along the left edge.

  • Duplicate the Border_Left GameObject once more to create Border_Right, then place it along the right edge.

Tip: Use zoom and pan controls (scroll wheel + right-click and drag) to align the borders accurately, but don’t worry about perfection — close enough is fine for now.


You now have all four walls in place, forming a boundary to contain gameplay and GameObjects within the screen area.


9. Lock the aspect ratio and adjust borders

To make sure your game always fits the screen the way you intend, you can set your Game view to a fixed aspect ratio. By default, Unity’s Game view uses a flexible Free Aspect mode, which can stretch or crop your game depending on window size. In this step, you’ll set a fixed 16:9 aspect ratio, which is a common screen format used on phones and monitors.


You then might need to adjust your screen borders to make sure they align correctly with the new display shape.



1. Change the Game view aspect ratio:


  • In the Game view, open the aspect ratio dropdown (likely labeled Free Aspect) and select 16:9.

2. Experiment with the Game view size:


  • Drag the edge of the Game view to see how the visible space changes.

  • Notice how a fixed aspect ratio maintains a consistent layout, while “Free Aspect” stretches it.

3. Adjust the borders to fit:


  • In the Scene view, use the Rect tool (press T) to reposition and resize the borders so they neatly frame the 16:9 camera bounds.

By locking the aspect ratio and resizing your borders, you ensure that your game layout looks correct no matter how wide or tall the player’s screen is.


10. Organize the Hierarchy window and Assets folder

As your project grows, good organization will save time and reduce confusion. In this step, you’ll group related GameObjects inside an empty parent GameObject and tidy up your Project window by moving assets into folders.



1. Group the borders in an empty GameObject:


  • Right-click in the Hierarchy window and select Create Empty.

  • Rename the new GameObject ”Borders”.

2. Move all border GameObjects inside the new parent:


  • Use Shift+click or Ctrl+click (macOS: Cmd+click) to select Border_Bottom, Border_Top, Border_Left, and Border_Right.

  • Drag them all into the Borders GameObject in the Hierarchy window.

3. Organize your Project window:


  • Use Ctrl+click (macOS: Cmd+click) to select all assets that aren’t in the Scenes folder (such as the DefaultVolumeProfile and InputSystem_Actions).

  • Drag them into the Settings folder to keep your project tidy.

Your scene and assets are now neatly organized, making it easier to find and modify elements as you build more features.


Optional Step

11. Optional: More things to try

Try these optional activities to challenge yourself, build your skills, and improve your project.


Each challenge is tagged as Easy, Medium, or Expert difficulty so that you know what to expect. You can complete one, all, or none of them — it’s totally up to you. If you’re not interested in doing these challenges, mark this step as complete and proceed to the next tutorial.


Easy: Save a custom layout


If you've arranged your Unity windows in a way you like, you can save that layout for future use.



  • In the upper-right corner of the Editor, open the Layout dropdown.

  • Select Save Layout…, give it a name like “2D Game Layout,” and save.

Medium: Change the colors of your obstacle and borders


Make your game feel more unique by customizing the color of your GameObjects.


  • In the Hierarchy window, select the Obstacle GameObject or one of the border GameObjects.

  • In the Inspector window, locate the Sprite Renderer component.

  • Select the Color swatch and select a new color in the Color window.

  • Repeat for each GameObject you want to recolor.


If your camera background still uses the default color, try adjusting that too:


  • Select the Main Camera in the Hierarchy window.

  • In the Inspector window, change the Background Type property from Skybox to Solid Color.

  • Select a background color that complements your new GameObject colors.

12. Next steps

You’ve built the foundation of your 2D game world by adding an obstacle, setting up the camera, adding screen boundaries, and organizing your scene.


In the next tutorial, you’ll bring your first obstacle to life by adding physics, colliders, and turning it into a flying prefab.


Complete this tutorial