- Home /
Gui Button zoom
Hi all,
var myTexture: Texture; function OnGUI() { if (GUI.Button(Rect(10,10,50,50),myTexture)) Debug.Log("Clicked the button with an image");
}
This is my button anyone know how i make the zoom effect button when the mouse is over this button?
Thanks in advance for Help
Answer by VincentRodriguez · Feb 13, 2012 at 10:25 AM
I think this will scale button :
var myTexture: Texture;
var myRect : Rect;
private var x = 10;
private var y = 10;
private var width = 50;
private var height = 50;
var sizeToGrowX = 10;
var sizeToGrowY = 10;
function Start ()
{
myRect =Rect(x,y,width,height);
}
function OnGUI()
{
if (GUI.Button(myRect,myTexture)) Debug.Log("Clicked the button with an image");
}
function Update ()
{
if(Input.mousePosition.x > x && Input.mousePosition.x < x+width)
{
if(Input.mousePosition.y > y && Input.mousePosition.y < y-height)
{
x-sizeToGrowX;
y-sizeToGrowY;
width+(sizeToGrowX*2);
height+(sizeToGrowY*2);
}
}
else if(Input.mousePosition.x < x && Input.mousePosition.x > x+width)
{
if(Input.mousePosition.y < y && Input.mousePosition.y > y-height)
{
x-sizeToGrowX;
y-sizeToGrowY;
width+(sizeToGrowX*2);
height+(sizeToGrowY*2);
}
}
}
can you format it, tht would be better for someone to understand?!
add this code to function Update if you want to scale texture as the button :
myTexture.width = width;
myTexture.height = height;
or this if want to texture would be smaller :
//variables outside function Update !!!
var $$anonymous$$usScaleTexX = 2;
var $$anonymous$$usScaleTexY = 2; //this inside function Update !!!
myTexture.width = width - $$anonymous$$usScaleTexX;
myTexture.height = height - $$anonymous$$usScaleTexY;
Your answer
Follow this Question
Related Questions
Make a Button out of a Textured Plane 2 Answers
Buttons and images 1 Answer
dirty lens effect over light help 1 Answer
GUI Button Texture only showing as small 1 Answer
GUI buttons look fine on full screen but distorted otherwise? 0 Answers