Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 unity_Y19j_WqZ7S9TLQ · Nov 26, 2017 at 12:18 AM · canvassaveload

Load game with Canvas button

I want to create a save game with only the name of the scene in which the player last stopped. I want the game to be saved whenever the player starts the next phase and when he returns to the game, when he presses on the main menu, he returns to where he left off.

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

1 Reply

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

Answer by smkmth · Nov 26, 2017 at 12:46 AM

You can get the name of the active scene you a currently in with SceneManager.GetActiveScene

https://docs.unity3d.com/540/Documentation/ScriptReference/SceneManagement.SceneManager.GetActiveScene.html

Remeber to add

using SceneMangement;

in the name space.

it actually gets the scene as a reference- so if you want to get the scenes name - i would say public void SaveGame{

string LastSceneName = SceneManagement.GetActiveScene().name;

}

then if its litearlly just the scene name that you need to to save and nothing else, the easiest way to save data is playerprefs. it sounds like you are doing a small project, and if so, i think player prefs might be fine for your purposes, although for a larger project saving data can be more intricate.

https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

heres the docs for player prefs, but ultimatly what you want to do is in the save method i wrote, add somthing like

PlayerPrefs.SetString("SavedSceneName", lastSceneName);

Then just drag and drop the object this method is on to the button's OnClick panel in the inspector. You can load the game with somthing like

public void LoadGame(){

string LoadLevelName = PlayerPrefs.GetString("SavedSceneName", "No Name");

if (LoadLevelName == "No Name"){

Debug.Log("Somthing wierd has gone on, check the name of the scene you tried to save - check the build order, this shouldnt really happen");

} else {

SceneManager.LoadScene(LoadLevelName, LoadSceneMode.Single);

}

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 unity_Y19j_WqZ7S9TLQ · Nov 26, 2017 at 01:23 AM 0
Share

Thank you so much, you've solved my problem.

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

79 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

Related Questions

Saving and loading data from file 0 Answers

Serialization scripting error 1 Answer

Cannot load a saved game 1 Answer

Saving/Load using menu C# 1 Answer

Loading a list into unity 0 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