Game Development Reference
In-Depth Information
myTexture = new Texture2D(125, 15);
}
void OnGUI() {
GUI.DrawTexture(new Rect(325, 15, 100, 15), myTexture);
}
Note that in all the examples providing a Texture, I have provided a
basic template to initialize an empty texture. In reality, you would be
assigning a proper texture to be drawn.
You can also provide scaling and alpha blending values when drawing the texture to
make it better it in the scene, including the ability to control the aspect ratio that the
texture is drawn in.
A warning though, when you scale the image, it affects the
rendering properties for that image under the legacy GUI system.
Scaling the image can also affect its drawn position. You may have
to offset the position it is drawn at sometimes.
For example:
public Texture2D myTexture;
void Start() {
myTexture = new Texture2D(125, 15);
}
void OnGUI() {
GUI.DrawTexture(new Rect(325, 15, 100, 15), myTexture,
ScaleMode.ScaleToFit,true,0.5f );
}
This will do its best to draw the source texture with in the drawn area with alpha
blending ( true ) and an aspect ratio of 0.5 . Feel free to play with these settings
to get your desired effect.
This is useful in certain scenarios in your game when you want a simple way to
draw a full screen image on the screen on top of all the 3D/2D elements, such as
pause or splash screen. However, like the Label control, it does not receive any
input events (see the Button control for that).
 
Search WWH ::




Custom Search