x


How can I see a UI while the game is running in the background?

To be more specific (b/c I know the title was a little confusing) : How do I make an area that is a GUI run with the game? For instance let's say the game was starcraft2 how would I put in the UI like sc's ( http://static.clanbase.com/CB/images/news/2009/screenshots/StarCraftII_UI_03.jpg )?

I heard about the helper class and manager. Will this help? if so can someone link documentation or how to make and use it?

Thank you very much

more ▼

asked Apr 13 '12 at 02:31 AM

Generic gravatar image

Generic
3 1 1

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Sure, here is an example script from the link : http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTexture.html

// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle.  Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.
var aTexture : Texture;

function OnGUI() 
{
    // check there is a texture to use
    if(!aTexture){
        Debug.LogError("Assign a Texture in the inspector.");
        return;
    }

    GUI.DrawTexture(Rect(10,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 0); // aspect ratio is 0 , true image scale displayed

    GUI.DrawTexture(Rect(150,10,60,60), aTexture, ScaleMode.ScaleToFit, false, 0.0); // no alphablend (no transparency)

    GUI.DrawTexture(Rect(80,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0); // apect of image is changed to ( 60 : 6 ), image is centred to the Rect

    GUI.DrawTexture(Rect(10,70,90,90), aTexture, ScaleMode.ScaleToFit, true, 0); // image is scaled to the size of the Rect given
}

So make a new script , copy in this code , then attach the script to your camera (well , any gameObject really). Then in the Inspector drop in your image with transparencies. After that , it's just a matter of getting the co-ordinates and scaling correct for where you want to place the images. This is handy as the Gui is using pixels, so you can work out your layout. Hope this gives some more information =]

more ▼

answered Apr 14 '12 at 03:00 AM

alucardj gravatar image

alucardj
13.9k 40 57 88

Thank you so much! This works great, thanks for posting.

Apr 14 '12 at 04:08 PM Generic
(comments are locked)
10|3000 characters needed characters left

Look at @alucardj answer for documentation links. If a camera has the GUILayer object added to it, it renders GUI objects. When you render GUI elements to the camera, the GUI elements will get overlayed over the 3D scene that the camera sees

Can I have a direct link on how to do this? I don't fully understand how I could do this without making a button. Also, does the alpha masked parts the picture that I'm using for the UI show the background instead?

more ▼

answered Apr 14 '12 at 02:11 AM

Generic gravatar image

Generic
3 1 1

(comments are locked)
10|3000 characters needed characters left

Look at @alucardj answer for documentation links. If a camera has the GUILayer object added to it, it renders GUI objects. When you render GUI elements to the camera, the GUI elements will get overlayed over the 3D scene that the camera sees.

more ▼

answered Apr 13 '12 at 03:43 AM

dkNinja gravatar image

dkNinja
91 2

Sorry, I didn't mean to be rude. I just thought that the answer needed a little bit more explanation besides the links to the documentation. I don't mind removing my answer if you add some explanation about the GUI. I just wanted to add the parts that I was confused about when I first read about the GUI in Unity.

Apr 13 '12 at 04:54 PM dkNinja

no worries , and I'm sorry too. You were right to suggest an explaination. I had this happening in other places, but here you are cool, you were just trying to help.

Apr 14 '12 at 02:55 AM alucardj
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x68
x8
x3

asked: Apr 13 '12 at 02:31 AM

Seen: 411 times

Last Updated: Apr 14 '12 at 04:08 PM