I have this script at the moment
var powerTxt : GUIText;
var BallsTxt : GUIText;
function OnGUI ()
{
powerTxt.pixelOffset = new Vector3(- Screen.width/2 + 650, Screen.height/2, 0);
BallsTxt.pixelOffset = new Vector3(- Screen.width/2 + 1000, Screen.height/2, 0);
}
How would I apply this to a texture 2D?
Thanks
GUIText are not GUI elements. The don’t have to be adjusted inside OnGUI(). In fact there are good reasons not to place the code inside OnGUI(). GUIText elements don’t require repeated OnGUI calls to exist, and OnGUI is executed multiple times per frame. So you are setting these values 200 times per frame when you could set them once in ‘Start()’.
A Texture2D is a class used to reference and manipulate a texture. By itself, it does not display images. You can use a GUITexture, or use GUI.DrawTexture, or others to display a texture.
In addition to the ‘pixelOffset’ values, GUIText lives in viewport space and is also positioned by the transform.position. The closest way to a GUIText to display an image is GUITexture. You can create one from the menu by: Game Object > Create Other > GUI Texture. You can drag and drop a texture onto the ‘Texture’ variable, or you can assign your Texture2D at runtime. In addition to changing the viewport coordinate, it has a ‘pixelInset’ for controlling positioning. It is similar to ‘pixelOffset’, but is a Rect. See:
http://docs.unity3d.com/Documentation/ScriptReference/GUITexture-pixelInset.html