Teleporting from one scene to another and back again with the same player gameobject

So I’m working on a project kind of like fallout, but as i was working on it i ran into a problem with doors.

I need to same player object to teleport to different scenes but also teleport back again.

(To make it easier to understand what i mean) World Scene > Interior Scene > World Scene

This is the script i’m using:

var ToLoad = "";

var player : GameObject;

var x : int;
var y : int;
var z : int;

function OnTriggerStay(){
    if(Input.GetKeyDown(KeyCode.E)){
        if (player.gameObject.name == "FPSController") {
            player.transform.position = Vector3(x, y, z);
       }

        Application.LoadLevel(ToLoad);
        Debug.Log("Hello World!");
    }
}

The player will teleport the right part of the other scene i send it to, but it can’t teleport back because the “player” gameobject on the trigger hasn’t got anything assigned to it because the player isn’t in the scene to begin with.

I tried working with teleporting anything with the same tag but it kept spitting errors at me like “cannot convert unity.gameobject” or something like that.

So is there a way to assign the “Player” object to the variable after its spawned in the scene or will i have to work with tags?

Anyway help would be greatly appreciated Thanks.

If you’re not going to reload the state of objects from one scene to another, then don’t. Mark the object(s) as do not destroy.

Please navigate over to the scripting section on DontDestroyOnLoad