- Home /
How to change rect size?
Hi,
I put down an empty gameobject and attached a script. With the script I added an image:
function OnGUI () {
GUI.DrawTexture(new Rect(25,200,30,1), fearBG);
}
Now I would like to change the height of this image through a function. How can I change the height in javascript?
I read it was possible by changing the pixel inset. However if I do the following, it won't work?
function testF() {
guiTexture.pixelInset.y = 50;
}
Answer by prototype7 · Sep 03, 2012 at 06:40 AM
Try this for showing what Eric5h5 means about GUITextures have nothing to do with OnGUI
var wasClicked = "";
function OnGUI(){
if(wasClicked == ""){
GUI.DrawTexture(new Rect(25,200,30,1), fearBG);
if(GUI.Button(new Rect((Screen.width/2)-100,(Screen.height/2)+50,200,30),"Options"))
{
testF();
}
}else if(wasClicked == "clicked")
GUI.DrawTexture(new Rect(25,200,30,50), fearBG);
}
function testF(){
wasClicked = "clicked";
}
Answer by Eric5h5 · Sep 03, 2012 at 02:50 AM
GUITextures have nothing to do with OnGUI code, so ignore all that. If you want to change the rect size, just, well, change the rect size. You have a rect there in OnGUI, so you can change the numbers as appropriate. The height that you have is 30, so change that to something else.
Thanks, but I need the height to be exactly the same as a variable. $$anonymous$$eaning if the variable "Counter" is set to 25, the height of the image has to be 25. This variable can change all the time, so the image should too. How do I do this?
Just put the variable in the rect. It sounds like you'd benefit from learning some basic program$$anonymous$$g...the language doesn't matter so much, just go through a course or some tutorials and pick up the basic concepts, which apply to all program$$anonymous$$g.
Your answer
Follow this Question
Related Questions
Scale GUI Texture From the Center. 1 Answer
PackTextures and DrawTexture 1 Answer
[Closed]GUI.DrawTexture inside GUI.DrawTexture 1 Answer
Texture on center bottom of screen 3 Answers