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.

Material.mainTexture

var mainTexture: Texture;

Description

The material's texture.

The same as using GetTexture or SetTexture with "_MainTex" name.

See Also: SetTexture, GetTexture.

	// Assign the texture exposed in the inspector the renderer's material

var texture : Texture; renderer.material.mainTexture = texture;

Another example:

	// Change renderer's texture each changeInterval/
	// seconds from the texture array defined in the inspector.

var textures : Texture[]; var changeInterval : float = 0.33;

function Update() { if( textures.length == 0 ) // nothing if no textures return;

// we want this texture index now var index : int = Time.time / changeInterval; // take a modulo with size so that animation repeats index = index % textures.length; // assign it renderer.material.mainTexture = textures[index]; }