- Home /
Question by
AfricanMoney · Apr 23, 2013 at 09:36 AM ·
javascriptscenechanging
How do I place a player in the right spot when I change scenes?
In my game when you go to a new scene I added the script to my player: DontDestroyOnLoad (this), and it works but when I do that it creates the player at the spot where I finished my old scene. How can I load the new scene and place my player at the spot I want it to be?
Note: Using JavaScript :)
Comment
Answer by alexanderbrevig · Apr 23, 2013 at 09:43 AM
You could place a game object in the scene where you want the player to be, and then locate that object and assume it's position after the scene is loaded.
// after the scene is loaded
// assume the position and rotation of the SpawnPosition GO
var target : GameObject;
target = GameObject.Find("SpawnPosition");
transform.position = target.transform.position;
transform.eulerAngles = target.transform.eulerAngles;
After this you may want to Destroy(target)
. Good luck!