- Home /
How to change level and spawn player into coordinates?
I need script on change level and so player was in exact location where I want him to be. Simple as that. I think I should use some sort of spawn point.
I made one and it looks like this:
var InFrontOfTheDoor = false;
var MyPlayer:GameObject;
private var drawGUI = false;
function Update ()
{
if (Input.GetKeyDown(KeyCode.E) && InFrontOfTheDoor == true)
{
Application.LoadLevel("mw_scene_02");
}
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
InFrontOfTheDoor = true;
drawGUI = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
InFrontOfTheDoor = false;
drawGUI = false;
}
}
function OnGUI ()
{
if (drawGUI == true)
{
GUI.Box (Rect (Screen.width*0.48-51, 300, 202, 22), "Press [E] to enter");
}
}
But player spawns in same coordinates as he was in previous scene. I need him to appear in precise location for example X: 1.5 ,Y: 2.5 ,Z: 10.0.
If you have any ideas about that please let me know. Thanks.
Answer by JSierraAKAMC · Oct 05, 2014 at 04:05 PM
What you need to do is create a simple spawn script or add a small portion of code to another script that runs when you change the level. Something like this should work:
//Attach this to the character
var spawnPosition : Vector3;
function Start(){
transform.position = spawnPosition;
}
I got your point, but in my situation I can't attach it to the player. I need coordinates to be in script on trigger which activates the next level. Any idea how? $$anonymous$$aybe I need to use function OnLevelWasLoaded?
Your answer
Follow this Question
Related Questions
How to run a script to only 1 player in a multiplayer fps 1 Answer
AI Script attached to Enemy and is Rotating around player 0 Answers
Erro in MultiPlayer 0 Answers
Damage script is screwed up...? what to do? 1 Answer
Player or character select 2 Answers