I am currently working on a game where the user can enter a building by walking up to the building and pressing the E key. When the player walks up to the building, it says “Press E to enter (building name)”, in this case the warehouse. That part works fine, the player easily loads into the warehouse when they stay on the trigger and press the E key.
When the player is in the warehouse, they can walk up to the warehouse door (Trigger) and press E to exit, and it leads them to my island scene. Now to my question. I am wondering when the player presses E to exit the warehouse, how can I determine where they spawn? I want the player to load outside of the warehouse, the same place they pressed the E key to enter the warehouse, so just outside the entrance to the warehouse. This may be a simple question, but I have no idea how to go about doing this.
I’ve looked at other topics similar to this, but couldn’t figure out how to tie it in with my question.
Bear with me, I have only been in Unity for about a week now, and have started writing scrips a few days ago, so I am very new to scripting, and this is my first post on UnityAnswers.
LoadWarehouseInterior.js (This is on the island scene, but this brings them inside the warehouse):
#pragma strict
var hud : boolean = false;
var checkKeyDown : boolean = false;
function OnGUI(){
if(hud == true){
GUI.Box(Rect(325,320,200,40), "Press E to enter Warehouse.");
if(Input.GetKeyDown("e")){
Application.LoadLevel("WarehouseInterior");
}
}
}
function OnTriggerStay () {
hud = true;
}
function OnTriggerExit (){
hud = false;
}
LoadWarehouseExterior.js (This should take them to my island, in the specified location):
#pragma strict
var hud : boolean = false;
var checkKeyDown : boolean = false;
function OnGUI(){
if(hud == true){
GUI.Box(Rect(325,320,200,40), "Press E to exit the Warehouse.");
if(Input.GetKeyDown("e")){
Application.LoadLevel("");
}
}
}
function OnTriggerStay () {
hud = true;
}
function OnTriggerExit (){
hud = false;
}
If it helps, I would like the player to spawn at the following coordinates - X: 2731, Y: 121, Z: 2071
Since I will have numerous buildings the player can enter, I would appreciate it if the player spawns to the certain specified spot, since each exited building should have its own spawn point.
So how would I go about doing this? Like I said, I am new to unity and scripting, so please be easy with me in your answers, and help is appreciated!