0
\$\begingroup\$

I am making my first GUI in unity, and I am not sure if should create the toggle buttons in the game scene by creating new UI elements or by scripting.

Creating them in the game scene gives me more options but I have trouble to manipulate the input.

Because of this I am scripting them in the monodeveloper but it seems more difficult to work the visual side (I am using a texture but can't get rid of the little box (that shows f the button is clicked or not).

How do you make your toggle buttons and how do you develop your GUI?

Any help appreciated.

\$\endgroup\$
2
  • \$\begingroup\$ what kind of trouble manipulating the input do you have? \$\endgroup\$
    – Eben
    Mar 4, 2016 at 17:24
  • 1
    \$\begingroup\$ I personally create the UI element in my scene whilst in edit mode. I make sure everything is lined up correctly and all scripts are attached. I then create a prefab out of it and whenever I need to in my game, I'll just instantiate it. Obviously this depends on whether I want it to stay in the scene (I.e: Health bar) or be destroyed (I.e: Pop-up text). At the end of the day either method is fine. If you run into performance issues then you can start to alter your way of generating UI. \$\endgroup\$
    – Mike Hunt
    Mar 4, 2016 at 21:32

3 Answers 3

0
\$\begingroup\$

I am using the canvas UI in Unity 5. And to add a button to screen, I just create a UI Image under my canvas object in Hierarchy view. Change the sprite as required.

Now add "Event Trigger" as shown below.

enter image description here

Next "Add new event type". I use "PointerUp".

Select the

You get an empty list.

enter image description here

Click + to add a function which will be called on the event ("PointerUp" in our case)

enter image description here

In the third field insert the object which should have the script (you want to invoke) attached to it. In my example the object is called "LevelUIControls" and it has a script called "LevelControls" attached to it.

enter image description here

This should make it easy for you to manipulate input.

\$\endgroup\$
0
\$\begingroup\$

I prefer the scripting way to make the GUI, though it's probably because the only thing I like about making games is scripting.


Slipting way :

One way to do it is to use the GUI.Toggle function in Unity.


Non Scripting Way :

If you still want to use the new GUI, here's a good tutorial : Click me :)

\$\endgroup\$
-1
\$\begingroup\$

I prefer UI Elements...

I mostly use UI Elements for static buttons and labels..

When I need dynamic stuff going on (an inventory for example) I just script-instantiate them (using object pools)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .