Posts Tagged ‘GUI’

Unity: Scaling the GUI based on the screen resolution

Click here to read Unity: Scaling the GUI based on the screen resolution

As hinted by other posts, here, you will find how to properly scale the GUI elements based on screen resolution. As one may have noticed, Unity doesn’t scale the GUI elements based on the screen resolution, requiring a script to do the job, which is explained in this post. I will assume that the reader already knows how to create and render GUI elements in Unity using the MonoBehaviour’s OnGUI() function and GUISkin objects.

The best way to explain how to properly scale a GUI element is through an example. That said, for this post, let’s assume that we wanted a yellow rectangle to be rendered at the top left and bottom right corners of the screen, like this: (more…)

Unity: How to use a GUI Texture to play fullscreen videos

Click here to read Unity: How to use a GUI Texture to play fullscreen videos

Warning: this tutorial only works with Unity Pro because the free version doesn’t come with video playback support. The code was created and tested with Unity version 3.3. It won’t work for versions 2.6 and below (requires some adaptation).

This Unity post explains how to set up a GUI Texture at the Unity editor and the code necessary to play a fullscreen video, that can be used for the studio logo animation at the beginning of the game, the game’s intro or any other video that needs to take the whole screen. It also explains how to properly scale the video based on the screen dimensions. At the end of the post, a Unity project featuring all the code explained here is available for download.

(more…)

Unity: How to create a GUI Sprite Sheet – Part 3

Click here to read Unity: How to create a GUI Sprite Sheet – Part 3

The final part of a series that explains how to create a GUI Sprite Sheet in Unity. This post will focus on explaining how the code works. For those who haven’t read the first and second parts, please do before going any further. As most post series in this website, there is a download with everything that had been explained at the end of the post.

With all images and the GUI Skin already set at the Unity Editor, now we just need some code to render the GUI on the screen. The following script correctly renders separately each element from the sprite sheet, and it’s attached to the Main Camera:

(more…)

Unity: How to create a GUI Sprite Sheet – Part 2

Click here to read Unity: How to create a GUI Sprite Sheet – Part 2

This is the second part of a series that will explain how to create a GUI sprite sheet for Unity. For this part, we will take the images created in the first post and import them to Unity. Also, this post features how to correctly set the images to be part of a GUI Skin object so they can be used as part of a game’s interface.

After having all images correctly placed at the sprite sheet, create a new GUI Skin by right-clicking anywhere inside the Project tab and select the following: Create->GUI Skin. Then, import the images in Unity, by dragging and dropping them inside this tab. It’s a good idea to put everything GUI related at the same folder, like this: (more…)

Unity: How to create a GUI Sprite Sheet – Part 1

Click here to read Unity: How to create a GUI Sprite Sheet – Part 1

This post is the first of a series that explains how to create a GUI sprite sheet (a.k.a. atlas map) in the Unity game engine. This map consists of buttons, text areas, backgrounds and other interface elements joined together to create various joined image files with all interface elements inside it.

Here, the focus will be on how to prepare and create this images at an image editing software, which is the most important step. The next post of this series will explain how to import these images in Unity and place them inside a GUI Skin object.

The first thing to do is to have all the GUI elements needed for the game or specific part of the game. They have to be already created before building the sprite sheet, at least their size have to be already defined. Throughout this post, the following GUI elements will be used to exemplify how to correctly join the images together:

(more…)