blog games developers documentation portfolio gallery

More in this category:

Using Texture2D+

Make sure you include the line

using Texture2DExtensions;
in your script.

Using the Texture2D+ class extensions can best be illustrated with an example:

using UnityEngine;
using System.Collections;

using Texture2DExtensions; // important!!!

public class MyClass : MonoBehaviour {
public Texture2D myTexture; // a texture assigned in the Editor

void Start () {
myTexture.Scale(Screen.width, Screen.height);

In this example the Texture is scaled to the same size as the Screen and could for instance be used as a background image.
Next the texture is desaturated to 50% to make is less destracting.

The new methods do not return a new Texture2D, but instead affect the Texture2D itself. If you want to preserve your original texture, you should clone it first. Like this:

myTexture = (Texture2D)Texture2D.Instantiate(baseTexture);

There are more examples to be found in DemoCtrl.cs

follow us