Search Unity

What is the best method for creating a 2D icon?

Discussion in 'Scripting' started by IainDaddy, Jul 20, 2013.

  1. IainDaddy

    IainDaddy

    Joined:
    May 29, 2013
    Posts:
    9
    Hello all,

    I have a simple space shooter game and would like to provide an instrument panel, as in FlightGear.

    I assume that the best method of doing this will be to use 2D icons with an added line as an indicator. For instance, the fuel gauge will have a full and empty scale already marked on it and I will just have to add a line to indicate the value. Of course, once I get going I will be working up from speed and compass to a radar and full HUD targeting system. :)

    Before I start on this I thought I would ask for opinions before I start causing bugs with the GD side of things as that looks like what I should be working with.

    So the question is: What do you think is the best method of producing a simple line drawn on a 2D graphic?

    Any help will be appreciated ... especially pointers to C# tutorials.

    All the best.

    Iain
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    If you can, Illustrator, is great for creating graphics. You can create a full atlas, a bunch of images, or just one. Port it to Photoshop, export the psd (photoshop document) to Unity.


    I am not sure how graphics especially HUD items tie in with code.
     
  3. IainDaddy

    IainDaddy

    Joined:
    May 29, 2013
    Posts:
    9
    Hi renman3000,

    Thanks, but yes, I can photoshop something together like this:

    $Untitled-1 copy.png

    Now I need to draw the pointer on there for the fuel level.

    I assume I can use the GUI screen to put it on my screen.

    All the best.

    Iain
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    For me, I do not concern my self with Unity's OnGui. I use Sprite Manager 2 and EZGUI. 2D Tool Kit is another handy asset. Please someone correct me if I am wrong, but unless Unity has finally released their new OnGui, OnGui is a pretty heavy cost to your engine. Also, I just do not like the abstraction of it.

    How I would set this up, create an atlas of all the images you would need for your HUD. Then, place that psd on a material. Then, in Sprite Manager 2 and or EZGUI, use a SimpleSprite component, to show any HUD graphic. Basically what I am doing is creating an object that would hold a sprite. So, any method that works I suppose.

    For the needle, just insure you have an object, that shows the sprite. Then, for the fuel, just create some script that tells how much fuel you have left as a percentage. What the min and max rotation values of the needle are. Then, as fuel goes down, adjust the rotation.
     
  5. e5an

    e5an

    Joined:
    Jul 6, 2012
    Posts:
    93
    I will second that about avoiding OnGui. I so disliked everything about how OnGUI() and UnityEngine.GUI work the first time I tried to use them I decided to design my games as if they didn't exist, and haven't had reason to go against that yet. You can build a gui out of textured quads,TextMeshes, box colliders, and an Animation component, and have a GUI camera attached to the main camera but on a higher render layer.

    Use a 2-point LineRenderer, or use a graphic of the needle on a black background in a particle additive shader and rotate its parent object, or just use a long thin cube model.
     
  6. IainDaddy

    IainDaddy

    Joined:
    May 29, 2013
    Posts:
    9
    I have to agree that the OnGUI interface is not the best thing and I do have trouble getting on with it. It seems it's bes use is for displaying debugging information. As for replacing it, sorry renman3000, but $150 to $200 for an upgrade is not something I would consider. The main reasons being that I'm still not used to Unity and, apart from it crashing every hour or so, I've not been able to get it to compile a game that will run in anything other than a web based windows browser. Perhaps in a few weeks, once I have got it to work. :)

    Yes, I had thought of using a 3D method of generating the dials and that would be easy for fuel level, speed, compass, etc. (although a fun exercise, I think the processor overhead may be a bit high) but this would not work for the radar and HUD... for that you need to be able to get the program to draw a line or a dot.

    $screenshot002.png As you see there is enough room for the HUD and it is an essential item as once the targets get a distance away you just can't see them on the screen so, if it was not for the attacker coming after me, I would not be able to find anything to shoot at. :(

    The fuel gage is just an example, the question is how to draw the line as I can think of lots of ways to put the graphic up once it is modified.

    Another application for the line drawing will be the targeting information, you will not want to shoot at a friendly, especially if they are a lot bigger than you. :D

    All the best.

    Iain