Applying Image Textures

Hi,

I have a texture image which has small images of each of my 3 levels.

I would like to be able to use the same image for 3 buttons. Right now I am doing the below but that obviously creates just one button.

var levelicon: Texture2D;
function OnGUI()
{
GUI.Button(Rect(10,10,150,450),GUIContent(levelicon));
}

How can I make it such that each button is assigned a separate part of the image as texture.

Also does the button have to be a rectangle or can be other shapes also like a circle.

Thanks,

Ads

Wether you create 3 textures, or you create new ones using SetPixels and GetPixels:

function Start () {
    // duplicate the original texture and assign to the material
    var texture : Texture2D = Instantiate(renderer.material.mainTexture);
    renderer.material.mainTexture = texture;

    // colors used to tint the first 3 mip levels
    var colors = new Color[3];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    var mipCount = Mathf.Min( 3, texture.mipmapCount );
    
    // tint each mip level
    for( var mip = 0; mip < mipCount; ++mip ) {
        var cols = texture.GetPixels( mip );
        for( var i = 0; i < cols.Length; ++i ) {
            cols[i] = Color.Lerp( cols[i], colors[mip], 0.33 );
        }
        texture.SetPixels( cols, mip );
    }
    
    // actually apply all SetPixels, don't recalculate mip levels
    texture.Apply( false );
}