Playtesting

First let's create a test scene; create a new scene and name it Saving and Loading Example. Within this scene, you have Main Camera, which we will use as our player. We need two more GameObjects for our enemies. For the enemies, I created two boxes and placed them randomly in the scene. I've named one of them Enemy1 and the other Enemy2. Here's what my scene looks like:

Playtesting

Where you place the camera and enemy boxes doesn't matter. As long as you have multiple objects to be your enemies, your test scene will be fine. Next, we will add the scripts to Main Camera. First, we will add the Flat_Save_System script.

In the SFile Name field, type in the name of the file that you want to write to. I've named mine PlayerData.txt. In the SDirectory field, type the directory you want to save the file to for the desktop type in C:UsersUSERNAMEDesktop. Type your username on your computer in place of username. Finally, drag Main Camera into the slot next to Player. Your inspector for that script should look something like the following screenshot.

Playtesting

Now, we will add the XML_Save_System script to the camera; go ahead and drag it over to get started. In the PFileName field, type in C:UsersUSERNAMEDesktopPlayerData.xml. Do the same for the EFileName field, except that you replace PlayerData.xml with EnemyData.xml. Drag main camera in the slot next to Player. In the Enemies dropdown, type in the number of enemies you have in your scene. Finally, drag your enemy GameObjects into your Enemies array. This is what my Inspector menu looks like:

Playtesting

Finally, drag the SaveHandler script to Main Camera. We will now start testing. Click on the Play button at the top, and once the scene has started, press the F1 key. Doing this will save the enemies' transform. Now click on the scene window, and move your enemy GameObject to a different location, rotate them, and change their size. Once you are done, press the F2 key. You will notice that the enemy GameObjects will return to their original transform.

Your XML file looks something like the next screenshot. Your XML file might have different values and possibly more enemies.

Playtesting

To test the flat file save system, open the SaveHandler script to change a couple of values. In the Update function, where we check for input, instead of calling SaveEnemies and LoadEnemies, call WriteToFile and ReadFile. When you test the scene, again press F1 to save. On your desktop, you will see a new file called PlayerData; open it and you should see several lines with numbers. These numbers are the variables you saved from the game.

If you want to customize your flat file save type and not allow players to easily see or edit the data, change the extension. Instead of saving it as .txt, save it as .save or anything you want. If the player tries to open it, the computer won't know how to open the file, but the game will still be able to use it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.170