playMaker

Author Topic: Persistent GUI-- with changed variables?  (Read 1690 times)

krane

  • Junior Playmaker
  • **
  • Posts: 63
Persistent GUI-- with changed variables?
« on: February 06, 2017, 11:51:04 AM »
I have a simple GUI with 4 navigation buttons (up, down, left, right).
Rather than recreate buttons on each scene, I'd like to have the GUI buttons stay on each scene, so would put it in a Don'tDestroyonLoad for the GUI.

How then would I change which scene the buttons refer to on each scene?
So for instance, on scene 1, up would go to scene 2, but on scene 2, up would go to scene 6.

I've tried setting global variables for Up, down, left, right, and then changing the variable on each scene by setting the global with a local, but I can't seem to get that working.

Is it possible to have something persist, while the variable it refers to change?

 

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Persistent GUI-- with changed variables?
« Reply #1 on: February 06, 2017, 12:51:38 PM »
Persists the buttons, and instead of statically assigning to buttons to load like Scene 1, by name or by number, just load the NEXT scene in order. With the new Unity's scene manager you can keep track of current, next, previous scenes and all that - it makes it pretty easy.

Current scene number + 1 = Next Scene
Current scene number - 1 = Previous Scene

helpful info: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
« Last Edit: February 06, 2017, 12:57:51 PM by elusiven »

krane

  • Junior Playmaker
  • **
  • Posts: 63
Re: Persistent GUI-- with changed variables?
« Reply #2 on: February 06, 2017, 04:23:18 PM »
Thanks, but if I have 4 directions and the player might go anywhere, how can I know what's next?

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Persistent GUI-- with changed variables?
« Reply #3 on: February 06, 2017, 05:41:22 PM »
Oh, sorry... I misunderstood your question here :P

Maybe it sounds like an overkill but I can't think of anything else, for a moment I thought you maybe ment like a grid system, but then it's scenes..I'm not sure how big the game is but I would probably store all the level info in xml or json, then when the game starts it would load it up, and based on the saved information it would update the button's actions to load the right scenes.. Or if you don't have lots of levels then make an FSM that persists and based on current scene, it sets up all the buttons actions to load the specific scenes. Maybe someone else can come up with a better solution :P