- Home /
Question by
youngapprentice · Aug 12, 2013 at 02:01 AM ·
materialcoloritweenslot
iTween.ColorTo on one material
Hi, all! I have multiple material slots assigned to my gameObject's renderer. I know I can assign them through code using renderer.materials[x] but I don't know how to do so through iTween. When I use it it just changes all material slots. Is there a way to do this?
Thanks! - YA
Comment
Should I just perform this operation with Color.Lerp?
Best Answer
Answer by socoman3 · Apr 01, 2015 at 03:50 AM
Hi there!
I used ValueTo instead of ColorTo, so you can apply it to the material you want in "onUpdate" method. Like this:
public float speedTween;
private Renderer myRenderer;
void Start()
{
myRenderer = GetComponent<Renderer> ();
iTween.Stop(gameObject);
iTween.ValueTo (gameObject, iTween.Hash ("from", Color.blue, "to", Color.red, "time", speedTween, "easetype", "easeInCubic", "onUpdate","UpdateColor"));
}
void UpdateColor(Color newColor)
{
myRenderer.materials [1].color = newColor;
}
GetComponent is used because in Unity 5 you are not able to use renderer.material directly.
Hope this helps