x


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:

  1. 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 :)

more ▼

asked Aug 18 '11 at 02:12 AM

WhipJr gravatar image

WhipJr
65 5 7 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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.

more ▼

answered Aug 18 '11 at 04:05 AM

Julien.Lynge gravatar image

Julien.Lynge
7.3k 20 25 49

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.

Aug 18 '11 at 08:41 PM WhipJr

Sure thing. If it works for you mark it as accepted so it gets taken off the unanswered list.

Aug 19 '11 at 04:30 AM Julien.Lynge
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1274
x801
x573
x440

asked: Aug 18 '11 at 02:12 AM

Seen: 773 times

Last Updated: Aug 19 '11 at 04:30 AM