Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help with .PNG image in GUI

Discussion in 'Immediate Mode GUI (IMGUI)' started by BoxOfMonkeys, May 10, 2011.

  1. BoxOfMonkeys

    BoxOfMonkeys

    Joined:
    May 9, 2011
    Posts:
    28
    Please can someone help me out?

    I'm trying to follow the tut on loading an image into a GUI button.

    So I got the PNG I wanted (a small file showing a stop icon) and did Assets --> Import New Asset. I can see it in the Inspector.

    Next I created a GUI script, did a Texture2D variable and assigned the PNG to the variable in the Inspector. Then I did the OnGUI event and attached the script to the camera. I can see the button - but no image.

    Am I doing something wrong?
     
  2. geetoo

    geetoo

    Joined:
    Apr 21, 2009
    Posts:
    42
    I'd like to help but can't find the tutorial you're talking about... Can you give the code inside your OnGUI function or provide a link to the tutorial please?
     
  3. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,273
    Working code from one of my games:
    Code (csharp):
    1.  
    2. var LaserIcon:Texture2D;
    3.  
    4. function OnGUI() {
    5.     var LaserRect:Rect = Rect(400, 10, 64, 64);
    6.     if (GUI.Button(LaserRect, LaserIcon)) {
    7.         MyNetwork.FireLaser();
    8.     }
    9. }
    10.  
     
  4. sawfish

    sawfish

    Joined:
    Feb 12, 2011
    Posts:
    314
    Doh, nevermind.