Entering a Building (Teleporting)

Hey everyone!
I’m working on “Life” Simulator, but does anyone know a script
where if I stand in a place and press a button, and then I teleport
to another location. I need it for a GTA: San Andreas style, building entering.
Or it could be a script if I stand in a place and press a button I go to another scene.

Thanks for reading :slight_smile:

It could be done with scene switching (there are other ways to do it, but the way GTA does it is by switching scenes or “levels”)

Use Application.LoadLevel(); to achieve that, you need to have more then one scene in your project, then go to ‘File → Build Settings’ and ‘Add Current’, this will add the current level to index 0 in that list (next level you add in there will be 1 and so on), the game will always load the scene in index 0 as default. Now, when you use Application.LoadLevel(); you can use either the index of the level you want to load, or the name of it (in string format). So Application.LoadLevel(“LevelOne”); or Application.LoadLevel(0);

I hope this is what you wanted/meant. You could otherwise just change the transform.location of your player character to whereever you want whenever you collide with your “teleport object”/“teleport area”.

Attach this to player. Then set your door’s tag to Door. Then assign the newLocation and your players gameObject in the inspector

 var newLocation : Transform;

 var player : Transform;

 function OnTriggerEnter(col : Collider){

           if(col.gameObject.tag == "Door")

      {

           if(Input.GetKey("f"))
 
           {

                gameObject.transform = newLocation;

           }

           else

          {

                gameObject.transform = player;

           }
 
      }

 }