- Home /
Question by
danhanly · May 22, 2012 at 03:02 PM ·
javascriptgameobjecttexture2dguitexture
New GameObject with GUITexture is a Horribly Incorrect Size
I've created a GameObject at runtime that I want to have a specific texture. Here's my code (JS):
if (!popUpVisible){
popup = new GameObject("Popup");
popup.transform.position = Vector3(0,0,2);
popup.AddComponent('GUITexture');
popup.guiTexture.pixelInset = new Rect(0,0,315,345);
popup.guiTexture.texture = popUpTexture;
popUpVisible = true;
}
In theory, this new game object should contain a new GUITexture at rect - 0,0,315,345. For a reason I cannot quite fathom it stretches and moves the texture so it looks ridiculous; a rect value which is closer to how it looks visually is 515,685,-650,-350 (I manually adjusted these values in the inspector to test).
I'm not sure what I'm doing wrong.
The texture is 315x345 and is correctly set as a GUI Texture.
Comment
Best Answer
Answer by Eric5h5 · May 22, 2012 at 03:11 PM
You have to set the scale to 0 if you want it to use pixel values.
I set popup.transform.localscale = Vector3.zero; now it works. Cheers for pointing me in the right direction!