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 /
This question was closed Jul 15, 2013 at 08:53 PM by davidflynn2 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by davidflynn2 · Jul 11, 2013 at 12:02 AM · guisave scene

UnitySerializer Delete Saved Games

I am trying to add a way for the player to delete their saved games. I am using Unity Serializer to create and load the save games but I have read though all the documentation and I can not figure out how to allow the player to delete a saved game. I have reworkd the save game some here is the script I have so far. I would also like to limit the saves they can have down to 5 but not sure that is just a side task though if the player could delete them I would be happy just not sure how to do it.

 using UnityEngine;
 using System.Collections;
 
 public class GrassPause : MonoBehaviour
 {
     
     public GUISkin Box;
     public GUISkin Box2;
     private string box;
     public string gameName = "Your Game";
     bool paused;
     
     
     void Update ()
     {
         if(Input.GetKeyUp(KeyCode.P))
     { 
        paused = !paused;
  
         if(paused == true){
             Time.timeScale = 0.0f;
             //if(pausedGUI) pausedGUI.enabled = true;
         } else {
             Time.timeScale = 1.0f;
           //  if(pausedGUI) pausedGUI.enabled = false;
         }
    }
 
         
     }
     
     
      void  OnGUI ()
     {
         if (paused)
         {
          GUILayout.BeginArea(new Rect(400,200, 300, 400));
         GUILayout.BeginVertical(); 
         GUILayout.FlexibleSpace();
             
             
             GUI.skin = Box;
             if(GUI.Button(new Rect(55,0,200,55),box))
                 {
                        LevelSerializer.SaveGame(gameName);
                 }
         GUILayout.Space(5);
                 foreach(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) 
                         { 
                            if(GUILayout.Button(sg.Caption)) 
                               { 
                                  LevelSerializer.LoadNow(sg.Data);
                                   Time.timeScale = 1;
                               } 
                      } 
             GUILayout.EndVertical();
             GUILayout.FlexibleSpace();
             GUILayout.EndArea();
         }
  
      }
 }
 
 
 
 
   
 
  
     
    
     
    
     
     
  
 
 
 
Comment
Add comment · Show 8
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 davidflynn2 · Jul 11, 2013 at 12:18 AM 0
Share

I found a way to add a button to delete all the saved games but I don't think any one would like to delete all most of the time they just want to delete one save game. Any way on doing this?

avatar image InfiniBuzz · Jul 11, 2013 at 12:22 AM 1
Share

you could do something like:

 foreach(var sg in LevelSerializer.SavedGames[LevelSerializer.PlayerName])
 {
    if(GUILayout.Button("Delete: " + sg.Caption))
    {
       sg.Delete();
 
    }
 } 

if you want to limit the savegames you can just setup a counter and check it before saving

avatar image InfiniBuzz · Jul 11, 2013 at 12:50 AM 1
Share

Sinply define a new integer: int _savedGames = 0;

And replace LevelSerializer.SaveGame(name) with:

 if(_savedGames <= 5)
 {
    LevelSerializer.SaveGame(gameName);
    _savedGames++;
 }

And after the delete Line put

_savedGames--;

Hope it helps

avatar image InfiniBuzz · Jul 11, 2013 at 01:09 AM 1
Share

I forgot about it but in your Awake function you can set

 LevelSerializer.$$anonymous$$axGames = 5;

Which is much easier :)

avatar image InfiniBuzz · Jul 11, 2013 at 08:29 AM 1
Share

And forget about the _savedGames variable (delete the lines you added for it

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Multiple Cars not working 1 Answer

Working With GUI 1 Answer

How do I center the gui created by this script? 0 Answers

UnityEngine.Input.GetMouseButton(1)) issue 1 Answer

How To Make GUI Buttons Load/Quit 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