Search Unity

Best practices for using similar GUI in every scene

Discussion in 'Game Design' started by jackson_31, Nov 7, 2015.

  1. jackson_31

    jackson_31

    Joined:
    Sep 20, 2014
    Posts:
    84
    I have multiple scenes. and each scene has a similar GUI however some icons differ between scenes.
    for example: here is my USA scene


    here is my CO scene


    to achieve the CO scene I dragged the entire canvas from the USA scene into the project view as a prefab, and then loaded the CO scene, copied the prefab onto the hierarchy, and then modified it for the CO scene.


    is this good practice?

    Should i instead create one generic Canavas prefab that is similar in all scenes and instanciate it on awake and then load other prefabs for different GUI objects in each scene?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    In 5.3 the recommended way is not using DontDestroyOnLoad but instead using the new multi scene support.

    ie. You have a scene for your UI and other scenes are loaded or unloaded as normal, with your main UI and setup scene always present at the root.

    If you don't want to use 5.3 multi scene editing, or don't have patience to wait for it, you can use http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html - but make sure this object is only ever loaded one time.
     
    Ryiah likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Or, use prefabs, as you originally suggested. There's absolutely nothing wrong with that.
     
  4. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    Yeah do that, because then if you want to change the prefab later on it will automatically update, if you dont you might end up with assets that have different data in each scene, get out of sync etc.
     
  5. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    This is the first I've heard of that, and I can't wait for it. I have code that specifically forces an object to be a cross-scene object. Being able to cut that won't remove a lot of code, but every little bit that I have to manage is more that I...well, have to manage. TL;DR - I looooove cutting code!

    It puts the lotion on its constructor...