- Home /
change player location after Application.Loadlevel
how would i go about changing the players location after Application.Loadlevel. i have a few scene that all link from one main one and would like to respawn back to the trigger that it exited the scene from, ive tried many way to do this but with no success, would you be able to help?
Answer by Aria-Lliane · Aug 21, 2013 at 01:12 AM
I'm no expert dont know if ill be of any help, but i do think that it very much depends on what you have... In a quick thought i think you could use "PlayerPrefs"
Example:
On a Script on the player's character inside scene '1':
void SavePosition(){
PlayerPrefs.SetFloat("PlayerPosX", this.transform.position.x);
PlayerPrefs.SetFloat("PlayerPosY", this.transform.position.y);
PlayerPrefs.SetFloat("PlayerPosZ", this.transform.position.z);
}
On the script in the character in scene '2':
void LoadPosition(){
this.transform.position.x = PlayerPrefs.GetFloat("PlayerPosX");
this.transform.position.y = PlayerPrefs.GetFloat("PlayerPosY");
this.transform.position.z = PlayerPrefs.GetFloat("PlayerPosZ");
}
Your answer
Follow this Question
Related Questions
Collision problem when spawning in the collider 1 Answer
Random spawn of object on trigger 3 Answers
How to Subtract the score 1 Answer
How to apply more than one trigger on a single gamebject 1 Answer
Do 2 Triggers Collide? 1 Answer