Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GUI.DrawTexture

static function DrawTexture(position: Rect, image: Texture, scaleMode: ScaleMode = ScaleMode.StretchToFill, alphaBlend: bool = true, imageAspect: float = 0): void;
static void DrawTexture(Rect position, Texture image, ScaleMode scaleMode = ScaleMode.StretchToFill, bool alphaBlend = true, float imageAspect = 0);
static def DrawTexture(position as Rect, image as Texture, scaleMode as ScaleMode = ScaleMode.StretchToFill, alphaBlend as bool = true, imageAspect as float = 0) as void

Parameters

positionRectangle on the screen to draw the texture within.
image Texture to display.
scaleModeHow to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.
alphaBlendWhether to apply alpha blending when drawing the image (enabled by default).
imageAspectAspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used. Pass in w/h for the desired aspect ratio. This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.

Description

Draw a texture within a rectangle.

	// Draws a texture in the left corner of the screen.
	// The texture is drawn in a window 60x60 pixels.
	// The source texture is given an aspect ratio of 10x1
	// and scaled to fit in the 60x60 rectangle.  Because
	// the aspect ratio is preserved, the texture will fit
	// inside a 60x10 pixel area of the screen rectangle.
	var aTexture : Texture;

function OnGUI() { if(!aTexture){ Debug.LogError("Assign a Texture in the inspector."); return; } GUI.DrawTexture(Rect(10,10,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0f); }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Texture aTexture;
    void OnGUI() {
        if (!aTexture) {
            Debug.LogError("Assign a Texture in the inspector.");
            return;
        }
        GUI.DrawTexture(new Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public aTexture as Texture

	def OnGUI() as void:
		if not aTexture:
			Debug.LogError('Assign a Texture in the inspector.')
			return
		GUI.DrawTexture(Rect(10, 10, 60, 60), aTexture, ScaleMode.ScaleToFit, true, 10.0F)