- Home /
commands.close.hint.6
how to make a character resume after going into a random battle?
i got my random battle generator working, now all i need is a way to save my character's position on one map so i can load a battle and fight, then after the battle resume exactly where he left off. like Final Fantasy VII's random encounters... i already know that it will have to do with vector3 and the character's transform data. but im not sure how i could keep track of that then use that information to respawn the character in that position.
answers that could help:
how to temporarily store vector3 data then re-use that info to spawn the character after the battle is over.
...thats about all i can think of that would really help actually...
if you can think of anything else that you think might help. please elaborate :)
Answer by Julien-Lynge · Aug 18, 2011 at 04:05 AM
I take your question to be 'how can I store data when loading a separate scene, then load the original scene again and access that data'. If that's not quite it, leave me a comment below.
To keep information between scenes, your easiest bet is probably to build some kind of 'backend' or 'scene controller' (call it what you will) that is generated once when you start up the game and follows the player around as they go to different scenes, keeping track of state information like their experience and what quests they have completed. You'll definitely need the dontDestroyOnLoad functionality. Pop your script in a gameObject in your Main Menu or Loading screen and fill it with info when the player selects 'Load' or 'Play'.
Further, I'd suggest making as many variables and functions static as possible, so you can call them without having to have a reference to a specific game object containing the script (using Find or whatnot). With static variables, you can access them with MyScriptName.varName (where MyScriptName corresponds to the C# class or the JS file name).
With that, your question becomes trivial: just before loading the other scene, load up your Vector3 myPositionBeforeFight (or whatever). Then, in an OnLevelWasLoaded call, restore the player to that position.
thank you or this reply, im not sure if its gonna help quite yet but it looks like its gonna help out a lot. im about to try and use some of this information in about 2 seconds and see how it works out. ill let yu know any problems.
Sure thing. If it works for you mark it as accepted so it gets taken off the unanswered list.