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

Button scripting style

Discussion in 'Scripting' started by benjaminver89, Oct 28, 2015.

  1. benjaminver89

    benjaminver89

    Joined:
    May 14, 2015
    Posts:
    30
    What i wanna do is to create a button (button were dynamically created) that looks like to Windows tills : perfect rectangle with an image that fill the background.
    Unfortunately, documentation on GUIStyle is very (very) succinct.
    Is there somebody that can help me ?
    Thanks
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    To make a GUIStyle, you need to create one first in the editor, set it's values, and then assign it to a variable as a GUIStyle. If you use the newer GUI, just assign it to it, if you use the legacy GUI system, then you need to put the GUIStyle to the end of the buttonscript: http://docs.unity3d.com/ScriptReference/GUI.Button.html. With the image, there's a variable for it too
     
  3. benjaminver89

    benjaminver89

    Joined:
    May 14, 2015
    Posts:
    30
    I don't wanna use editor, only scrpting.

    I finaly found something :

    -Create a new GUIStyle. GUIStyle mygui;
    -Apply to buttons. GUI.Button (new Rect (0,0, 355, 200), (Texture2D), mygui)
    It will only show button content (image), not the shape

    -import texture as a Sprite
    You will be able to get right propotion and no a 2^n