I found already some things - but those seem not quite what I need. (perhaps outdated functions?)
https://docs.unity3d.com/ScriptReference/Material-shader.html
here, it seems you can add a shader to a renderer:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Shader shader1;
public Shader shader2;
public Renderer rend;
void Start() {
rend = GetComponent<Renderer>();
shader1 = Shader.Find("Diffuse");
shader2 = Shader.Find("Transparent/Diffuse");
}
void Update() {
if (Input.GetButtonDown("Jump"))
if (rend.material.shader == shader1)
rend.material.shader = shader2;
else
rend.material.shader = shader1;
}
}
well - i dont have a renderer. i only have a material.
and there is no "material.setShader" , only a material.setTexture"
sooo can anyone solve this mystery of how to add a shader to a material via script?
.shader
property. Or is your actual question how to get a reference to a specific material in your project assets? \$\endgroup\$theMaterial
and a shader with the variabletheShader
, it should just betheMaterial.shader = theShader
. When that does not work, you should finally post your own code so we can see where your mistake is. \$\endgroup\$