Playground Pattern: Door to a New Level

This tutorial will explain how to create a door that will transfer the player to a new level, using Unity Playground. You could also use this to take the player to a winning screen when reaching a goal.

Required Tasks or Knowledge

  • Player Movement setup
  • Environment setup
  • A sprite to act as the transition trigger (door, portal, goal, etc)

Video Tutorial

Step 1 – Organise your two levels into two separate scenes

You will need a copy of your player in both scenes. In the second level’s scene, choose the starting position the player should be in after they go through the door.

Step 2 – In the first Level, drag your “Door” sprite into the scene to create a GameObject

Note: This doesn’t have to actually be a door – it could be a portal, goal flag, etc. Whatever it is, when the player touches it, they will go to the new scene.

Step 3 – Add the “Condition – Area” component to the Door GameObject

A popup will ask what type of collider to add. Usually a Rectangle (Box Collider 2D) is a good choice for doors, but any will work.

Step 4 – Tick “Filter by Tag” and choose “Player” as the Tag to check for

This will prevent your door from being operated by enemies or other GameObjects, which would cause the scene to transition unexpectedly.

Step 5 – Select your player and change their tag to Player if not already set

In order for the Condition Area tag check to work and let your player through to the next scene, the player has to be using the “Player” tag. Select it from the Tag dropdown at the top of the Player’s inspector.

Step 6 – Select your Door again and add a LoadLevelAction to the Gameplay Actions list.

Add to the list by clicking the plus sign to the lower right corner of the Gameplay Actions box on the Door’s Condition Area component. This will add a new component to the door – the Load Level Action component.

Step 7 – Open the Build Settings and add your levels to the scene list

Open the Build Settings from the menu (File > Build Settings…). The top half of this window will have a list of scenes, which will be empty unless you have already added your scenes here. Find your Level 1 and Level 2 scenes in your Project window and drag the scene files into the Build Settings window.

Close the Build Settings window when you are done – do NOT click “Build” or “Build and Run”.

Step 8 – Select your Door and choose the level you want to load in the Load Level Action

You should now have a list of scenes in the Load Level Action component on your door, under “Scene to load”. Choose the scene you want to load when the player touches this door.

Step 9 – Test!

Try moving your player on to the door – they should transition to the next scene!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s