Going from Town to Battle to Town

I’m making a turn-based battle game in Unity3D and I have 2 scenes (a town scene and a battle scene). Whenever the character meets a monster, the game jumps to the battle scene where the character does battle and go back to the town scene after defeating or losing.

The problem is how to return to the town scene with the same state as when the character enters the battle scene (character position, statuses, etc.)

if I use

Application.LoadLevel(‘battlescene’);

then

Application.loadLevel(‘townScene’);

then the townScene will start from the first time. How to make the townScene continue from where we left off?

Look at DontDestroyOnLoad. It keeps things safe from scene changes and such, but you will probably have to rethink how your character works to make it how you want it… or make character stats and such separate from the physical char in the scenes.

1 Like

Hello.

Thank you for the quick reply.

I will look more at DontDestroyOnLoad.Would my guy still start at the start point and not where he was upon entering battle. I have playerPrefs for some of the status. I wonder if a checkpoint system would work for saving a new temp startPoint?

I could be way off on this. Thank you very much again.

Well there are 2 main ways to do this.

If you don’t destroy your character, you will need to set up some spawn points in your scenes where you can set your character’s location to when whatever happens. You whole character remains between scene loads and such.

If you pull the character script off of your character (and put a reference to the actual character to do whatever with)… and just have it on an empty game object that isn’t destroyed… then you can change / load scenes and spawn your character however and just assign it to the script

1 Like

Hello.

Thank you very much. I will give this a go when I get home tonight. This is really helpful and is pointing in the right direction.

Thank you again.