DrawTexture and Resources.Load()

This is a way to draw a button on screen.

void OnGUI(){
	GUI.DrawTexture(new Rect(0,0,64,64), (Texture)Resources.Load("GUI/btn"));
}

Is it bad ? Does unity reload the “GUI/btn” each frame ?

Thanks

Yes, the GUI Button (or any GUI element for that matter) is redrawn every frame. So by loading your graphic into the button it will cause the file to load every single frame (3o times a second).

Typically, you will create a variable in the Start() function to hold your texture, and then reference that variable in your GUI Element.

var icon : Texture;

function OnGUI () 
{
    GUI.Button (Rect (0, 0, 100, 20), GUIContent (icon));
}