- Home /
How to change speed transition between materials
Hi,
I am using an IU button in my scene, this button changes the material of my character, I have 7 different materials.
Now this script works fine but I want to change the speed transition between materials.
Any Advice would be more than welcome
var myMaterials : Material[];
var NextMaterial : int = 0;
function NextMaterialUsed()
{
GetComponent.<Renderer>().sharedMaterial = myMaterials[NextMaterial];
if(NextMaterial < myMaterials.length-1)
NextMaterial += 1;
else
NextMaterial = 0;
}
Answer by DiegoSLTS · Oct 14, 2015 at 06:51 PM
Setting a speed for the transition between materials? Like doing a smooth change "lerping" between them? I don't think that's possible, or at least not easy.
The only thing I can imagine is having 2 meshes overlapped, each with a different material. One is fully transparent and the other is not, and you change the transparency of both at the same time to simulate a smooth transition.
If you just ment to delay the transition some time just write a coroutine. I think something like this should work in JS as a starting point:
var myMaterials : Material[];
var NextMaterial : int = 0;
function NextMaterialUsed()
{
yield WaitForSeconds(1f);
GetComponent.<Renderer>().sharedMaterial = myMaterials[NextMaterial];
if(NextMaterial < myMaterials.length-1)
NextMaterial += 1;
else
NextMaterial = 0;
}
Answer by paco morales · Oct 14, 2015 at 07:01 PM
Diego thanks for your replay, Yes I want to delay the transition...
I did check your script but the console tells me this "ArgumentException: method return type is incompatible"
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612041315im_/https://answers.unity.com/themes/thub/images/avi.jpg)