- Home /
Change GuiTexture.Pixelinset.width changes It's position!
Hi,
I have a GuiTexture.the pixelinset.width is 512.when change it to 100,it's position move to left!but in inspector positions does not change! What is the problem?how can fix it?
Thanks
Is the texture width getting smaller when you change it?
Answer by aldonaletto · Jul 12, 2011 at 12:38 AM
EDITED (again...): GUITexture.pixelInset is the rectangle where the texture will be drawn, and its bottom-left corner coordinates are relative to the point defined by Position. If you modify width, x must be modified too in order to keep the alignment. This will keep the GUITexture at the position already defined:
guiTexture.pixelInset.width = newWidth;
guiTexture.pixelInset.x = -newWidth/2;
The same applies to height and y:
guiTexture.pixelInset.height = newHeight;
guiTexture.pixelInset.y = -newHeight/2;
Question edited to correct an imprecise information about the rectangles's bottom-left corner.
It works, I sware! $$anonymous$$aybe the problem is that I stupidly wrote GUITexture.pixelInset ins$$anonymous$$d of guiTexture.pixelInset. I've edited my answer (again!), now it's correct. Try it; this works even for negative width and height.