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.shader

var shader: Shader;
Shader shader;
shader as Shader

Description

The shader used by the material.

See Also: Shader.Find method, Materials, ShaderLab documentation.ad.

	// Toggle between Diffuse and Transparent/Diffuse shaders
	// when space key is pressed

var shader1 : Shader = Shader.Find("Diffuse"); var shader2 : Shader = Shader.Find("Transparent/Diffuse");

function Update() { if (Input.GetButtonDown("Jump")) { if( renderer.material.shader == shader1 ) renderer.material.shader = shader2; else renderer.material.shader = shader1; } }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Shader shader1 = Shader.Find("Diffuse");
    public Shader shader2 = Shader.Find("Transparent/Diffuse");
    void Update() {
        if (Input.GetButtonDown("Jump"))
            if (renderer.material.shader == shader1)
                renderer.material.shader = shader2;
            else
                renderer.material.shader = shader1;
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public shader1 as Shader = Shader.Find('Diffuse')

	public shader2 as Shader = Shader.Find('Transparent/Diffuse')

	def Update() as void:
		if Input.GetButtonDown('Jump'):
			if renderer.material.shader == shader1:
				renderer.material.shader = shader2
			else:
				renderer.material.shader = shader1