Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by Whutchison · Feb 09, 2013 at 11:52 PM · playerprefssaving

[Please Help!]How do I make a player save their position when I pause the game?

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AngryCSharpNerd · May 22, 2013 at 09:08 PM

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;
 }
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whutchison · May 22, 2013 at 09:50 PM 0
Share

Dude, this is wonderful. I could do JavaScript too. Thanks like a whole lot. This is truly great.

Whutchison

avatar image moghes · May 22, 2013 at 11:51 PM 0
Share

@Whutchison please set the answer as true, as I see your comment, you can also up vote as well, but a correct answer has to be set as true:)

avatar image Whutchison · May 23, 2013 at 03:46 PM 0
Share

Ok, if I pause it, will the screen like freeze, or will text appear or something to let me or the player know that the game is paused? I see that it will pause and it will save the position but how do I know if the game has been stopped or paused?

avatar image roojerry · May 23, 2013 at 03:53 PM 0
Share

for help on pausing the game check here

if you want text or a menu to appear for the user, a good place to start would be Unity GUI

avatar image AngryCSharpNerd · May 23, 2013 at 07:25 PM 0
Share

@Whutch

Actually, by pausing, nothing will happen and neither will text freeze. That's just saving the position for what I wrote. So you'll need to do an OnGUI() function, I don't know C# too much (irony of my name) so you can look that up elsewhere and have an if statement of "if(isPaused == true)".

 //Also, add this into the **O**nPause() function:
 
 AudioListener.pause = true; //This will pause sound from co$$anonymous$$g in
 AudioListener.volume = 0; //Just to make sure, no volume either
 Time.timeScale = 0.0; //This is what pauses the game. Say 0.5 and it's slo-mo!
 
 //Add this into the **U**nPause() function:
 
 AudioListener.pause = false; //Have sound play
 AudioListener.volume = 1; //Sound up
 Time.timeScale = 1.0; //Back to normal
 

(You might need to add an 'F' to the numbers because it's C#, that means "float")

Ask me anything if you need more help

Show more comments
avatar image
1

Answer by roojerry · May 22, 2013 at 08:42 PM

you could look at PlayerPrefs for a place to store that position data.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whutchison · May 22, 2013 at 09:51 PM 0
Share

Ok, I'll keep this in $$anonymous$$d.

avatar image
0

Answer by Stormizin · May 22, 2013 at 08:38 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whutchison · May 22, 2013 at 09:51 PM 0
Share

Isn't instantiate used in projectiles like bullets? Or is a much more of a broad function?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create a save and load game proccess like SCP: Containment Breach? 0 Answers

Save Values On Closing of Game 1 Answer

Saving Location in Unity 1 Answer

Questions about changes to UnityEngine.Random. Random.Seed deprecated 3 Answers

How to save players rotation in Unity? PlayerPrefs 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges