kavehmb2000
kavehmb2000

Reputation: 327

what is the best practice in creating menus in unity?

in the mobile game we are designing there exists three somehow similar menus:

now, there are at least two ways I can think of creating these menus:

As the assets used in both cases will be the same (well, in second case maybe more game objects) which one is a better solution? I can write the script as easily as I can create menus (both take almost the same amount of time to develope)

Upvotes: 1

Views: 2698

Answers (2)

user3071284
user3071284

Reputation: 7100

I recommend having one Canvas with multiple panels. Each panel can be for a different menu (main, pause, game over) or a different set of options in the same menu (main, settings).

Have a script on the Canvas with places to drag each panel. Then turn on/off the panels from code.

You can also create a script to attach to the panels, which has public Button variables, which you can assign in the inspector. The Button objects you drag there in the inspector can be prefabs, so you can reuse them in any menu.

The more reuse you have, the more efficient it will be.

Upvotes: 2

I would recommend to make some kind of MenuViewManager class, with ability to load menu view from XML file. This can lead you to nice translation system in the future and can be very responsive for changes.

Here I've found some article, which can help you start: http://unitynoobs.blogspot.com/2011/02/xml-loading-data-from-xml-file.html

Upvotes: 2

Related Questions