OnGui Function help

Hello Will. Doubt you will reply but on the off chance. I am using function OnGui and need when an object is click for it to change the image in a texture. much like the tutorial above but a bit more advanced.

var tex1 : Texture2D; var tex2 : Texture2D;

function OnGui{

if(GUILayout.Buttin((tex1), GUILayout.width(119),GUILayout.Height(119))){ Destroy(GameObject.FindWithTag(bike)); Instantiate(bigWheel2, Vector3(13,13,-507),Quaternion.identity); guiTexture.texture = tex2;



However i get the following error message: MissingComponentException: There is no GUITexture attatched to the ramp game object, but a script is trying to access it. You probably need to add the GUITexture to the game object ramp or your script needs to check if the component is attatched before using it.

It is definatly attatched to ramp so i need to check if its attatched before using it. How do i do this? i have tried if statements like:

if(tex1){ guiTexture.texture = tex2; }

but that doesnt work. any ideas?

error handling:

var tex1:Texture2D;

function OnGUI(){

 if(tex1 != null){  <<------It should work.
   if(GUI.Button(Rect(10,10,100,20), tex1)
   //blah blah
 } else {
   Debug.Log ("Please assign the texture.");