rect not resizing when button is

Hey guys!
I have a problem.

why does GuiButton (with the Rect being defined INSIDE the variable) and Gui.DrawTexture(defining the rect in the beginning of the script), produce different results? The Button (with the rect being defined inside of it) is resizeable, but the other one isn’t?

(resizeable = I drag the window around - the button / texture stays at the same relative position with the same relative size to screen size.)

private var r8 = Rect(Screen.width*0.85,Screen.height*0.51,Screen.width*0.1,Screen.width*0.1);

var buttonTexture : Texture;


function OnGUI()
{
	GUI.Button(Rect(Screen.width*0.85,Screen.height*0.51,Screen.width*0.1,Screen.width*0.1), buttonTexture);
	GUI.DrawTexture(r8, buttonTexture);
}

Your “r8” variable is defined once, and will never change. The other button recomputes the rect every frame.

–Eric

private var r8;
var buttonTexture : Texture;

function OnGUI()
{
    r8 = Rect(Screen.width*0.85,Screen.height*0.51,Screen.width*0.1,Screen.width*0.1);
    GUI.Button(Rect(Screen.width*0.85,Screen.height*0.51,Screen.width*0.1,Screen.width*0.1), buttonTexture);
    GUI.DrawTexture(r8, buttonTexture);
}

That should fix it.

-Tom

Sorry! I don’t know what I was thinking! Thanks a lot! I have a different question now though.

I’m using multiple buttons on a touch interface (for up to 4 people), which means I’m having my own way of using the touches.
However, when I’m defining a rect in which the user should touch (in order to activate a function), the texture rects and “touch” rects aren’t in the same place (even if they are using the same values).

How do I go about with this?

my example

private var r3 = Rect(Screen.width*0.37,Screen.height*0.8,Screen.width*0.1,Screen.width*0.1);

var buttonTexture : Texture;


function OnGUI()
{
	GUI.DrawTexture(r3, buttonTexture);
}

function Update () 
{
	if (Input.touchCount > 0)
	{
		if(r3.Contains(Input.touches[0].position)) 
		{
	
	    	Debug.Log("BUTTON THREE");
		}
        }
}

Can anyone help me with this issue?

TL;DR - When I touch a rect, the touch needs to be positioned SLIGHTLY next to the texture (that is based on the same rect). How do I align them up?