Game Development Reference
In-Depth Information
Step 9. To get back from the sewer room to the outside scene you
need to replicate the previous task. Double-click on sewerScene in the
Project to open it. There is a first person controller in this scene too.
Note that it is not the same first person controller as the outside scene
and therefore does not have the teleport code attached.
Step 10. Create a cube like the previous one and place it in front of
the door at the top of the sewer room. Tag it with toOutside .
Step 11. Create a JavaScript file named teleportOutside and add the code
from Listing 6.19 , except replace toSewer with toOutside and change the
scene name from sewerScene to outside .
Step 12. Attach teleportOutside to the First Person Controller.
Step 13. Play. You will now be able to teleport back and forth between
the outside scene and the inside scene.
6.5.2 Explicit Teleports
Explicitly transporting from one location to another in the same scene
works in a similar way. Now we are going to create a set of particle
systems that teleport the player from one location to another.
Step 1. Import the particles package used in the previous workshop
into the current project.
Step 2. Place a Sparkle Rising particle system on the ground near the door.
Step 3. Add a box collider to the particle system and resize to fit
around the particles.
Step 4. Rename the particle system in the Hierarchy to Sparkle1.
Step 5. Duplicate Sparkle1 and rename Sparkle2.
Step 6. Place Sparkle2 somewhere else in the game environment,
for example, on the roof of the factory.
Step 7. Create a JavaScript file named teleportTo and add the code
from Listing 6.20 .
Listing 6.20 Script to Reposition a Colliding Game Object
at the Position of Another Game Object
var to: GameObject;
function OnTriggerEnter(obj: Collider)
obj.gameObject.transform.position = to.transform.
obj.gameObject.transform.position.x =
obj.gameObject.transform.position.x + 1;
Attach this script to Sparkle1 and Sparkle2. Any game object with a
collider attached that enters Sparkle1 will automatically be teleported to
the position of Sparkle2. This not only includes the player's character, but
any game object that might be thrown into it. Think portal .
Search Nedrilad ::

Custom Search