How can I make the player save their current position in the scene when I press the P button to open pause menu and reload when the player continues their game after closing and reopening the game? What I’m trying to say is that if I open the pause menu I want the game to save their position and then load after closing the menu.
Please provide a script, tutorial, and try to make it c#.
Thanks so much if you can.
I’m sorry that I’m not a a C# person, but basically, it would be like:
Vector3 savedPos;
Transform player;
bool isPaused = false;
void Update(){
if(Input.GetKey("P") && isPaused == false){
OnPause();
}
else if(Input.GetKey("P") && isPaused == true){
UnPause();
}
}
void OnPause(){
savedPos = player.position;
isPaused = true;
player.position = savedPos;
}
void UnPause(){
player.position = savedPos;
isPaused = false;
}
you could look at PlayerPrefs for a place to store that position data.
Use transform.position and insert in the database.
Then when you start the game again instantiate him in this last transform.position
The transform.position will return you the (x,y,z) in the world.