Teleporters¶
A teleporter is a trigger area that sends the player somewhere else: to another spot in the same
scene, or into another scene, like the door of a house. This page covers the Teleporter prefab,
its fields and what you need for teleports between scenes.
Concept¶
TeleporterBehaviour sits on a GameObject with a trigger BoxCollider. When the player stands
in the box and presses the activation key, or simply walks in if you set it up that way, the
player is moved to the position of another GameObject, found by name.
The destination is usually another teleporter, so the player can walk back. Any GameObject with the right name works as a landing spot, though.
In the demos, the door of the house in demo1 Big Map and the one in demo2 Farm House lead into demo3 Player House.
How to use it¶
- Drag
Samples/Prefabs/Teleporterinto the scene and place it over the door. - Resize its
Box Colliderto cover the area the player has to stand in. - Set
Target Teleporter Nameto the name of the GameObject the player should land on. - For a destination in another scene, set
Target Scene Nameto that scene's name and add the scene to Build Settings (see below). - Give every teleporter in a scene its own GameObject name. Names are how teleporters find each other, including the link back.
The prefab also has a HelpText component that shows a flashing Press "Enter" to go inside tip
while the player is within Distance From Player To Appear units of the teleporter.
Flashing Frequency is how many times per second it flashes.
Reference¶
| Field | What it does |
|---|---|
Target Scene Name |
The scene to load, by name without the path or .unity. Leave it empty, or set it to the current scene's name, to teleport within this scene. |
Target Teleporter Name |
The name of the GameObject the player lands on. The player takes its x and y and keeps its own z. |
Link With Target |
When on, the teleporter you land on is pointed back here: its target scene and target teleporter are set to this scene and this teleporter. Walk into it and you come back. The change only lasts while playing. |
Activation Key |
The key that fires the teleporter while the player stands inside it. Return (Enter) by default. Read through RpgInput. |
Teleport On Enter |
Fire as soon as the player walks in, with no key press. |
Note
For a teleport into another scene, the link back is always made, whatever Link With Target
is set to on the teleporter you used.
What counts as the player¶
Only a GameObject with a PlayerController sets a teleporter off, and its 3D collider has to be on
that same GameObject, with a Rigidbody so trigger events fire. The Player, PlayerTouch and
PlayerTileMovement prefabs are set up that way. Vehicles and enemies don't set it off.
The activation key is ignored for the first half second after a scene loads, so a key held down while arriving does not send you straight back.
With Teleport On Enter, arriving inside another teleporter could bounce you back at once. A
short cooldown shared by all teleporters (10 frames) stops that. Since 1.6.1 it is reset when play
mode starts, so it also works with Enter Play Mode Options set to skip the domain reload. Before
that, a value left from an earlier session could stop every Teleport On Enter teleporter from
firing.
Teleporting to another scene¶
The teleporter loads the target scene by name. A player build can only load scenes that are in the scene list of the build settings. Since 1.6.1, play mode in the editor loads any scene in the project, so the doors work there without setup. If the scene cannot be found, the teleporter logs a warning that names it and the player stays put. For a build:
- Open
File > Build Settings(File > Build Profilesin Unity 6, where the list is underScene List). - Drag both scenes, the one you leave and the one you arrive in, into the scene list.
For the demos, the welcome window (Tools > RpgMapEditor > Welcome) has an
Add Demos to Build Settings button that adds all five.
If the scene is missing, Unity logs an error that it could not be loaded and the player stays put.
The player survives the scene change because PlayerController keeps the first player with
DontDestroyOnLoad. You can leave a Player in every scene so each one plays on its own when you
open it. After a teleport, the scene's own copy is destroyed and the player you arrived with takes
its place.
When the new scene loads, the player is moved to the GameObject named Target Teleporter Name. If
there is none, the Console shows "Teleport destination not found" with the name, and the player
keeps the coordinates it had in the scene it left.