Search Unity

Icon definition

Discussion in 'Scripting' started by Gilead7, May 21, 2009.

  1. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    I've been going through the scripting tutorial.
    One of the things it is able to do is display an image along with buttons and text on a drawn box. The only definition given is: var icon : Texture2D; it makes no mention of the location or the name of the image that should be used. In the example the unity logo is displayed. Where do you tell it what image to use?

    Plus, can use you a 3d object, or flash file or ... etc?
    I'd like for one scripted area to have the torch I made show up glowing and fiery.

    Thanks!

    Code (csharp):
    1. var icon : Texture2D;
    2.  
    3.  
    4. function OnGUI () {
    5.     // Make a background box
    6.     GUI.Box (Rect (20,20,Screen.width,Screen.height), "Loader Menu");
    7.  
    8.     // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
    9.     GUI.Label (Rect (25, 25, 100, 30), "You see A stairway before you. Do you");
    10.  
    11.    
    12.     if (GUI.Button (Rect (20,50,80,20), "Take stairway")) {
    13.         print("You took the stairs");
    14.     }
    15.  
    16.     // Make the second button.
    17.     if (GUI.Button (Rect (20,90,80,20), "Leave")) {
    18.         print("You leave");
    19.     }
    20.     if (Time.time % 2 < 1) {
    21.         if (GUI.Button (Rect (20,110,200,20), "Meet the flashing button")) {
    22.             print ("You clicked the flashing button!");
    23. }
    24. }
    25. }
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    When you declare a variable like that and attach the script to some game object, the variable then shows up in the inspector when you select the game object. At that point you can drag any texture you have in your project on to the variable and assign that as the texture to use. Alternatively you can click the small dropdown arrow next to the variable value in the inspector and select a texture from there.

    You must use a texture object, and that means only the texture formats we support (PSD, PNG, BMP, JPG, GIF, etc.). If you want it animated then you can either use a movie texture (Unity Pro only) or you'll have to re-write the code to flip through a series of non-animated textures yourself.


    Tip: please familiarize yourself with using the code tags inside your posts. You can use the Code button above the post editor or manually wrap it in [ code ] and [ /code ] (without those spaces) tags. I edited your post above as an example, go into edit more yourself and you'll see! :)
     
  3. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    I did find it in the inspector and I changed it to a known texture I'm using for walls. I then clicked play. Not only did the texture not appear, but the entire window was missing. Where did I go wrong?
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    What "window" are you referring to? Or are you talking about your box? Either way, your code works for me as is (there are some spacing/layout issues to solve but it shows up just fine).


    Also, you define icon as a variable then never actually use it in your cited code. Are you expecting to see that in particular at this point?