Back to the gameStates - resuming a game

8 views
Skip to first unread message

Declan "scoby" Costello

unread,
Jun 10, 2012, 11:14:07 AM6/10/12
to Unity3d Ireland
I've been going through the code that Mark gave us for keeping
gamestates

GameManager which has a dictionary of gameStates

PlayingGameState
MainMenuGameState

I've added some GUI buttons for switching between states and it all
works well.

When I start a new game, PlayingGameState gets loaded
from there I can click back to load MainMenuGameState

from there when I click Resume I'd like to get back to the
PlayingGameState as I left it
but it's recreated anew each time.


I notice that in the GameManager Awake function there's a
DontDestroyOnLoad(this);

I tried putting that into PlayingGameSates OnActivate() function
but it isn't in scope and I want to know if I'm even on the right
track with this



GameManager
http://pastebin.com/9XXpVBns


PlayingGameState
http://pastebin.com/bVUCkwGr

Thanks for any help

Declan.

Ronan

unread,
Jun 11, 2012, 6:43:15 PM6/11/12
to Unity3d Ireland
Hey Declan,

The game states aren't Monobehaviours, so they aren't going to exist
as components in the scene. DontDestroyOnLoad would only apply to
objects or components in a scene. Your states are stored in the
dictionary, and should be preserved as long as the GameManager exists.

I don't see any information stored in the PlayingGameState class
though... Are you changing scene while swapping states? That would
wipe your scene when you change, and when you change back it would
load the scene from the start.

Ronan

On Jun 10, 11:14 am, "Declan \"scoby\" Costello" <dec...@tanigen.com>
wrote:
> PlayingGameStatehttp://pastebin.com/bVUCkwGr
Reply all
Reply to author
Forward
0 new messages