Hello! i have a little trouble here, i’m making and RPG and when some enemy touch the player it change the scene to a battle scene, and when the player wins, it changes back to the scene. The problem is that the scene will be reloaded, that means the enemy will be still there, there’s any way that i stop the scene and change it to the battle scene and then turn back when the player wins like how everything was (and destroy the enemy) or just tell the engine that that enemy was destroyed and never spawn again? Thanks if you taked the time to read and help me.
Now you’re getting into building save files. The easiest way to achieve this would be PlayerPrefs. I think JSON is a little more complex, kinda, but a little more secure too. If you are looking for more security and encryption, the way to go is Binary files. This can be complicated depending on your understanding of the language or maybe if you know C++ then not so difficult because the concept is generally the same. (Where you open and close streams)
With PlayerPrefs, there’s no real security and your files can be accessed by people that know how to do it. However, if you don’t care about that, it’s a good way to go.
You want to store your player’s Transform.position so that when you return to the scene he will be in the same spot. You’d do the same thing for each game object that you want to be there when you return. You can use a list or array to store enemies,or whatever else you may have, by using FindObjectsOfType(maybe your player has a special circle collider for a certain range and you use OnTriggerStay2D to determine what to save?). Then use a foreach() to loop through the list/array and store the information into your save file.
When you return to the scene, access the saved data and instantiate it accordingly to the Transform.position.