- Home /
LeanTween alpha materials
I am wishing to change the alpha of a gameobjects material using LeanTween. At the moment this can be done via the LeanTween.alpha property and works. However I have a lot of objects that share the same material that I would like to optimise by just changing the materials alpha and it would then apply to all objects using this material.
As it stands I have 3 sets of colored material (red, green, blue) and I store all gameobjects with those color tags into arrays (so redArray has 8 objects, blueArray had 6 and greenArray has 4). The code then needs to loop through each array and change the material alpha of each gameObject. (So 8 calls in the case of red) I would find it much easier to assign the Material to the script and then call LeanTween.alpha(Material, to, time). (Which should just be 1 call)
Is this something that could be added in the future?
Cheers
Answer by cstlmode · Jun 24, 2016 at 05:02 AM
use this instead
var mat :material; //the material you want to change the color LeanTween.Value(StartColor,EndColor, Time ).setOnUpdate(UpdateMat) ;
function updatemat(MyColor:Color){
mat.color=MyColor;
}
Yeah, I would go with this answer. Anytime you want to do something pretty custom it can usually be carried out with LeanTween.value.
Great, that was along the lines that I was looking for. I modified it a bit to get it working with what I want and in C#.
A follow on from this would be the ability to break the tween if the function gets called again before it has finished running. For example, I am wanting the colour to quickly come from low alpha to full alpha, then fade back down. For this, I use an Enumerator and works for the most part. However if I quickly run the function again before it has returned to initial alpha value, it sort of pops.
$$anonymous$$aterial mats;
Color blue = new Color(0,86/255,255/255,1);
Color fadeBlue = new Color(0,86/255,255/255,0.2f);
void BlueSplash()
{
StartCoroutine ("BlueSplashe");
}
IEnumerator BlueSplashe()
{
LeanTween.value(gameObject, fadeBlue, blue, 0.3f).setOnUpdate( (Color val)=>{
mats.color = val;
} );
yield return new WaitForSeconds (0.3f);
LeanTween.value(gameObject, blue, fadeBlue, 1f).setOnUpdate( (Color val)=>{
mats.color = val;
}
$$anonymous$$aybe there needs to be a new variable that stores the current val and uses that as the first argument in the value function? Or is there a way to tell Lean Tween to stop all current tweens?
Cheers