clicking on a GUI.DrawTexture

Hello , I’m making a menu and using custom buttons with GUI.DrawTexture
but i can’t make an if statement so that i can make the button clickable
here’s the script

 var GuiTexture : Texture2D;
    var rect1 : float = 297.6; 
    var rect2 : float = 69.4 ;
    var rect3 : float = 213.6 ;
    var rect4 : float = 89.3 ;
    var rect5 : float = 800 ;
    var rect6 : float = 600 ;
    var rect7 : float = 800 ;
    var rect8 : float = 600 ;
    var click : AudioClip;
    function OnGUI()
    {
        GUI.DrawTexture(ResizeGUI(Rect(rect1, rect2, rect3, rect4)), GuiTexture);
    }    
     
    function ResizeGUI(_rect : Rect) : Rect
    {
        var FilScreenWidth = _rect.width / rect5;
        var rectWidth = FilScreenWidth * Screen.width;
        var FilScreenHeight = _rect.height / rect6;
        var rectHeight = FilScreenHeight * Screen.height;
        var rectX = (_rect.x / rect7) * Screen.width;
        var rectY = (_rect.y / rect8) * Screen.height;
     
        return Rect(rectX,rectY,rectWidth,rectHeight);
        }

I want that when I click the texture , It loads level 1 for example …
Thanks in advance :slight_smile:

Use GUI.Button instead…

if(GUI.Button(aRect, aTexture)) {
    ///Load the level
}

GUI.Button Documentation

Why not just use GUI Styles to make a button just a texture?

var Texture1 : GUIStyle;
var Texture2 : GUIStyle;

function OnGUI() {
	if(GUI.Button(new Rect(10, 10, 100, 100), "", Texture1)) {
		//Code Here
	}
}

Then in the inspector go to your GUI Style and drag your texture in the box under “Normal”. That’s what I always do, it’s really easy.