Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by Sad_Man30 · Jan 08, 2021 at 07:05 AM · 2d gametopdownrpg

how to load a different save position in different scene?

I have 2 scene, one is the main menu and one is the main game. in the game i place may save point and in the main menu i have a 2 button, 1 is new game and 1 is continue. what i already did is i can play the new game simple by loading the second scene, but for continue i cant load the previous save point by using playerprefs. only the continue button in my game is the one not functioning right

this is my code for the save point

 public class save : MonoBehaviour
 {
     public bool triggered;
     public Animator anito;
 
 
    void OnTriggerEnter2D(Collider2D cut)
     {
         if (cut.gameObject.CompareTag("Player"))
         {
             anito.SetBool("save", true);
             PlayerPrefs.SetFloat("PlayerX", transform.position.x);
             PlayerPrefs.SetFloat("PlayerY", transform.position.y);
             PlayerPrefs.SetFloat("PlayerZ", transform.position.z);
             PlayerPrefs.SetInt("Saved", 1);
             PlayerPrefs.Save();
             triggered = true;
         }
     }
 
     void OnTriggerExit2D(Collider2D cut)
     {
         if (cut.gameObject.CompareTag("Player"))
         {
             anito.SetBool("save", false);
             triggered = false;
         }
     }
 }

and this is for the continue button this code work if the continue button is in the same scene. obj2 is the player object

 public void continuegame()
     {
         obj2.transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"), PlayerPrefs.GetFloat("PlayerZ"));
         obj3.SetActive(false);
         obj4.SetActive(true);
     }

Comment
Add comment · Show 1
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 Sad_Man30 · Jan 11, 2021 at 01:55 PM 0
Share

so it seem impossible to do sad

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Llama_w_2Ls · Jan 11, 2021 at 02:12 PM

I think I get what your problem is. When loading a new scene, the object in question is given the position in the editor, and not the saved position. Can't you use a script on the start method of the object, that runs this code transform.position = new Vector3(PlayerPrefs.GetFloat("PlayerX"), PlayerPrefs.GetFloat("PlayerY"), PlayerPrefs.GetFloat("PlayerZ")); and if the floats were not found (e.g. New Game), don't run that line? @Sad_Man30

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 Sad_Man30 · Jan 12, 2021 at 08:45 AM 0
Share

is the only way to call the other scene is this Scene$$anonymous$$anager.LoadScene("SampleScene");??

avatar image Llama_w_2Ls Sad_Man30 · Jan 12, 2021 at 08:47 AM 0
Share

Pretty much. You have to use the Scene$$anonymous$$anager.

avatar image Sad_Man30 Sad_Man30 · Jan 12, 2021 at 09:22 AM 0
Share

what i want to happen is to call the other scene but load it save point. the continue button is in the main scene and the save point is in the sample scene. for me to get to the other scene i use that Scene$$anonymous$$anager.LoadScene("SampleScene"); but it always reset the scene so it will always load at the start.

avatar image Llama_w_2Ls Sad_Man30 · Jan 12, 2021 at 09:49 AM 0
Share

Could you not use PlayerPrefs, to access the position of the save point from any scene?

Show more comments

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

148 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

[ANSWERED]UNDERTALE Game Over screen [2D] 1 Answer

8-directional orientation, top down 2D, seperate from movement 0 Answers

2d top-down rpg direction check 1 Answer

how to call a inactive object? 2 Answers

2D raycast shooting in the wrong direction 1 Answer


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