Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

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

Material.shader

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public var shader: Shader;
public Shader shader;
public 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