Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+13 votes

Does anyone have any good tips or tutorials on creating a UI within Unity, such as for an app or some such? Thank you!

asked in CSC490_Spring2019 by (1 point)

1 Answer

+5 votes
Best answer

See my response here for an overview on what types of UI are available, along with some video tutorials for the current standard method of creating UI. You should look at those if you don't know the basic basics of Unity UI, as I will assume here that you either know or can quickly intuit things like Canvas components.

If you know CSS and are familiar with web development UI concepts, you might want to opt for the UIElements route, present in the newer Unity versions (2019.2+), though you should be aware it's not fully feature complete yet.

This answer will focus primarily on the code aspect of UI, not the design, and will be focused on uGUI, as I am not personally very familiar with UIElements yet. Documentation is a lot faster than video tutorials here, in my opinion, so I'll link a decent amount of it.

As I understand it, most uGUI components by default accept touchscreen input the same as mouse input, so there shouldn't be any issue with simple multi-platform input, as long as you know how to use builtin Unity events. If you require more complex UI than the usual buttons and sliders and such (like multi touch, gyroscope interaction, etc.), you might want to use the mobile input (docs here, under 'Mobile Devices'), and if you are wanting at least semi-complex input over multiple platforms you might opt to you the new Input System (docs here).

If you are not aware of how to set up the builtin events, see the tutorials in my linked response or the documentation for one of them, which has a pretty straightforward example. You can also search for any component/element/event/etc. you would like documentation on in the documentation for UI. It might look sparse, but it is fully documented if you check the package links, etc. Sometimes googling might be more effective to find a relevant page.

If you really hate reading documentation, or find something unclear in it, you can always look up a tutorial specific to what you need help on. There's pretty much a tutorial for everything out there. Looking through the docs might help you get some more specific keywords, though.

There are also other alternatives such as choosing to use a package from someone else, or going with a 'code-free' option, though I imagine these are not applicable to you.

As far as other aspects of UI, you might want to look at animating your UI components. While animation isn't strictly required, it does make your app/game/whatever look a lot better.

Animation of any component in Unity is often done by using the builtin animation/timeline tool. You basically record an animation by setting component values on certain keyframes. The shortcut to bring up the animator is ctrl+6. You'll need to make an animation as well as an animator state machine, as well as an Animator component on the object you wish to animate, and then trigger the animations through code, either by directly setting the animation or by changing a value for the animator state machine to automatically control the animation. This probably sounds complex, but it's fairly simple in practice, and gives an astounding amount of control. I would recommend looking up a few videos on this, as it's so simple once you see it.

Here's a video tutorial for the animator from Unity, and here's a video tutorial from one of my favorite Unity tutorial makers on the timeline.

An alternative to the animation tool is to use tweening, which essentially does the same thing but through code exclusively. For anything more complex, though, I'd strongly recommend the animator/timeline tools, as it's much easier to manage multiple states and such.

answered by (1 point)
selected by