Unity 3D Game Engine – Materials – Switch Materials

1. Project> RMB> Create> Material> Create: material1 and material2

2. MAIN TOP MENU> Gameobject> Create Other> Cube, assign the script:

SwitchMaterial.JS


#pragma strict

	var material1 : Material; // assign in Inspector
	var material2 : Material; // assign in Inspector
	var transitionTime = 2.0;

	function Start () {
	}

	function Update () {
	ChangeMaterial();
	
	}
	
	function ChangeMaterial () {
		renderer.material = material1;
		yield WaitForSeconds (transitionTime); // wait seconds... -> non può essere inserito all'interno di Update()
		renderer.material = material2;         // switch to material2
		
	}

3. Project DRAG AND DROP material1 and material2 over Inspector> SwitchMaterial.JS> material1 slot | material2 slot