Create a temporary material from a shader source string.
// Creates an additive-blended material and uses it for rendering var color = Color.white; function Start () { var shaderText = "Shader \"Alpha Additive\" {" + "Properties { _Color (\"Main Color\", Color) = (1,1,1,0) }" + "SubShader {" + " Tags { \"Queue\" = \"Transparent\" }" + " Pass {" + " Blend One One ZWrite Off ColorMask RGB" + " Material { Diffuse [_Color] Ambient [_Color] }" + " Lighting On" + " SetTexture [_Dummy] { combine primary double, primary }" + " }" + "}" + "}"; renderer.material = new Material( shaderText ); renderer.material.color = color; }
Create a temporary Material from a Shader.
// Creates a material from shader&texture references var shader : Shader; var texture : Texture; var color : Color; function Start () { renderer.material = new Material (shader); renderer.material.mainTexture = texture; renderer.material.color = color; }
// Creates a cube and assigns a material with a builtin Specular shader. function Start () { var cube = GameObject.CreatePrimitive (PrimitiveType.Cube); cube.renderer.material = new Material (Shader.Find("Specular")); }