How do I make a Auto-resizeable GUI button that has a Texture in it that performs a command when pressed on. I know how to do this in JS, just not C#.
It’s the same in C# as JS.
–Eric
if(GUI.Button(Rect(Screen.width0.455 , Screen.height.41, Screen.width*0.1 , Screen.height/5), Security))
{
Spawn();
this doesn’t seem to work with c#
Well, you need to use C# syntax of course, but that’s unrelated to the question. You need to use “new” when making a Rect, and append “f” to floats.
–Eric
Thank you, it works (: Now how do I get the image within the GUI Button to stretch into the size of the GUI
You can use a GUISkin for this.
public GUISkin _Skin;
void OnGUI() {
GUI.skin = _Skin;
}
You can create a GUISkin by right clicking in your Assets and selecing New > GUISkin, drag it into your inspector and if you click on the GUISkin you can set custom labels, buttons and more. In the options here should be toggles to stretch the width and height. To use a custom property it’s as easy as doing this inside your OnGUI:
if(GUI.Button(new Rect(Screen.width*0.455f , Screen.height*.41f, Screen.width*0.1f , Screen.height/5f), Security, "NameYouGaveYourCustomProperty"))