Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Teleport scene to scene

Discussion in 'Scripting' started by xelvod, Jun 8, 2015.

  1. xelvod

    xelvod

    Joined:
    May 15, 2012
    Posts:
    90
    Hi,

    I need help with script.
    Script teleports my FpsControler to another scene on specific spawn point. But it start switching me betwin scenes because i spawn on teleport. Im stuck with this whole day.
    Can somebody help me with this script?
    Im just trying to make something like in Skyrim when you press button and enter to House interior from outdoor scene and back.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var SpawnPoint : Transform[];//variable with array to enable multiple spawn points to be added
    4.  
    5. function Start () {
    6.  
    7. }
    8.  
    9. function Update () {
    10.  
    11. }
    12.  
    13. function OnTriggerEnter (man : Collider) { //basic trigger function
    14.  
    15.     Application.LoadLevel("House_Int1");
    16.  
    17.     if (man.GetComponent.<Collider>().tag == "Player") {
    18.         var element : int = Random.Range (0,SpawnPoint.length);
    19.         man.transform.position = SpawnPoint[element].position;
    20.  
    21.         }
    22.  
    23.         else {
    24.  
    25.         }
    26.  
    27. }
     
  2. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Are you working with physical layers? If not, you are currently triggering a an Application.LoadLevel every time your game object collides with anything at all.
     
  3. JakeLeB

    JakeLeB

    Joined:
    Apr 18, 2013
    Posts:
    25
    If you're only trying to achieve the effect of walking into a house, you could always create a Spawner?

    Create a Cube and disable the collider on it, place it where you want the Player to be spawned when joining that Scene and create a Script attached to the Cube, in the Script use move the Player to the Cubes Position and rotation on Start.

    Then in the main-game world have these same Cubes placed at the doors facing the world, when you walk into one save the Transform to your Player in a Script so that if the Scene is equal to your World Scene spawn back at the last known Cube. I'd leave the collider attached to these Cubes though and set the Trigger to True.

    If you have issues with your Player you could Spawn the player in at runtime and have it set to not destroy on load, then have a check in the spawn script to see if a player is already spawned, if not spawn one.