Hot answers tagged

79

I'd argue that HUDs are graphical user interfaces: they're ways to present information back to the user graphically. In contrast to what some other answers say, the term GUI doesn't require that every element be directly interactive - the label next to a control on a form is still part of the GUI, guiding the player in how to interact with the system, even ...


26

Interactivity. A HUD is not interactive: it displays information only, it cannot be clicked, dragged, closed, etc. A GUI in a game is like any other UI: it is interactive. It has menus, buttons, scrollbars and other UI elements. The term Head Up Display refers to fighter jets: displaying information on a canopy means that the pilot does not need to look ...


23

There's a super simple way to change events: EDIT See my other answer for the quick and easy way to add an event for the OnClick event only. For other events, like OnDrag see below. Additionally, if you need more than just the events provided by default, I'd suggest instead attaching a EventTrigger to your game object. This gives us access to the ...


18

It's easy: Fonts do not need to match resolution, they need to match pixel density. Pixel density is measured as pixels per inch(PPI), or pixels per centimeter. There's also a measure unit called density independent pixels(DP). It is defined that 1dp is the size one pixel has on a 160 PPI screen. Now coming back to fonts, try to make this test: put your ...


15

The Navigation property of buttons is set to Automatic by default, allowing you to navigate through buttons using arrow keys. If you disable this by changing the Navigation property to None, buttons will not stay highlighted.


15

Finally I found a way to do it (tested in v5.0.0), in a way that: Does not need code, or conditionals to check orientation. Does not hack with scales and neither needs a reference resolution. In the UI video tutorials, there is a big part missing, although well documented in the text-documentation: The "auto-layouts" system. Auto-layouts are mechanisms ...


12

You can implement IPointerEnter and IPointerExit interfaces and keep boolean for 'over state': using System; using UnityEngine; using UnityEngine.EventSystems; public class TestOver : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { public bool isOver = false; public void OnPointerEnter(PointerEventData eventData) { Debug....


12

Here's a strategy for making arbitrarily bent UI: we'll render our UI into a texture (in realtime, not as a baking step), and then map that texture onto whatever mesh we want. Here's how I made this spherical example: Create a RenderTexture to store the UI. This needs to be quite high-res to get text looking crisp. I used 4096x2048 because I intend to map ...


12

Alright my dude. Welcome to the hell that is layout groups. Here's a few things you'll need to know first: If nothing is sizing the object, the layout group will not work as you expect (in fact it appears the opposite). Things that size the object include LayoutElement and ContentSizeFitter. For whatever reason the default rect transform sizings make the ...


11

The word is that the delegate{} syntax found in my previous answer is obsolete, there is another way of doing this using lambda notation: void buttonSetup(Button button) { //Remove the existing events button.onClick.RemoveAllListeners(); //Add your new event using lambda notation button.onClick.AddListener (handleButton); } void ...


11

Its entirely possible. Here's a simple script showing how. using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; public class PopulateSprites : MonoBehaviour { public List<Sprite> Sprites = new List<Sprite>(); //List of Sprites added from the Editor to be created as GameObjects at runtime public ...


11

I personally only see it as being bad for two reasons: It is very outdated and deprecated. And, It is much slower than the modern ways of drawing with OpenGL. But, if it's working out, and performance isn't going to be an issue, and if it is not a problem for you to use deprecated OpenGL functions in your program, then I believe you could do it. It will be ...


10

This is not technically an answer to your question, but is a better work around in my opinion. You can pass the dimensions of the boxes and the radius of the corners to the fragment shaders and round the corners that way. Basically, you take the current texture coordinates, multiply each coordinate of it by the dimensions of the window to get the ...


9

I think what you are looking for is something like following: GameObject CreateText(Transform canvas_transform, float x, float y, string text_to_print, int font_size, Color text_color) { GameObject UItextGO = new GameObject("Text2"); UItextGO.transform.SetParent(canvas_transform); RectTransform trans = UItextGO.AddComponent<RectTransform>(...


8

You can do this with the code below: title.color = new Color(254.0f/255.0f, 152.0f/255.0f, 203.0f/255.0f);


8

It is a bad idea insofar as it is nonsensical. There is nothing to "set up" that you have not already done, except for an ortho projection matrix (which you will have to do in any case). Portability is probably not a problem, although it should be. IHVs seem to be very reluctant to drop support for immediate mode for the foreseeable future (it seems to "...


7

Let's call the content you want to scroll content and the viewable area of that content viewPort. Your scrollbars will be at the sides of the viewport. The first step is to create a mask such that only parts within content which intersect with viewPort are visible. I can't answer exactly how to do this because it depends on your language and technologies. ...


7

Here is a rather simple extension class that you can use. public static class GraphicExtensions { /// <summary> /// Fade methods forUI elements; /// </summary> /// <param name="g"></param> public static void FadeIn(this Graphic g) { g.GetComponent<CanvasRenderer>().SetAlpha(0f); g.CrossFadeAlpha(1f, ....


6

Don't forget that every object in .NET has a ToString() method. Many of the built-in value types accept an optional formatting argument; numeric types in particular are easy to format with standard formatting or custom formatting. For example, instead of just passing cur_health, you could pass cur_health.ToString("n0"). For the specific question, you could ...


6

Call this function from inside OnInspectorGUI method to draw the automatic inspector. It is useful you don't want to redo the entire inspector, but you want to add a few buttons to it. http://docs.unity3d.com/ScriptReference/Editor.DrawDefaultInspector.html // This example shows a custom inspector for an // object "MyPlayer", which has a variable speed. ...


6

First of all, ensure you set the parent before setting local position, then, you have two options according to the type of Rect Transform : non-stretching and stretching ones. For a non-stretching Rect Transform, the position is set most easily by setting the anchoredPosition and the sizeDelta properties. The anchoredPosition specifies the position of the ...


6

The default behavior for Unity's UI is to draw after the post-processing effects have been applied. This is dictated by the Render Mode setting on your scene's Canvas object. Switch the Render Mode to Screen Space - Camera, and drag your scene's main camera into the Render Camera property (which will appear when you change the render mode). Now your canvas'...


6

Is a HUD part of the GUI and just displaying information? Yes. Head Up Display (as the name suggests) is just to display information while you are in-game. However in some scenarios HUD may be intractable. For example in a mobile based game there are on screen buttons to perform different actions while you are in-game.


5

After using several entity-component systems, especially CraftyJS, I more or less got the answer to my question: yes, you can reuse components (especially sprites or images and mouse-click handlers in 2D games) for the GUI. Much of the time, you only have access to the ECS, and not the underlying systems (eg. drawing system). In this case, it's okay to use ...


5

To have the gun heat up quickly but reach its overheat threshold slowly, you could take the gun's current temperature into account in the heat dissipation, rather than having a constant rate of heat dispersion. That's actually how it works in the real world: the rate of heat / thermal transfer is proportional to the difference in temperature. Wikipedia has a ...


5

You have the freedom to create your own button class, attach to it a sprite, make some methods to handle input and you're good to go. public class SimpleButton { private Sprite skin; public SimpleButton(Texture texture, float x, float y, float width, float height) { skin = new Sprite(texture); // your image skin.setPosition(x, y); ...


Only top voted, non community-wiki answers of a minimum length are eligible