- Home /
Question by
Jessespike · Jun 05, 2014 at 09:49 PM ·
errormaterialplugin
HoTween: Having trouble tweening a material's color
I'm trying to lerp a material's color with HoTween, but I'm getting an error:
Material doesn't have a color property ''
I have a scene that contains a cube and the cube has it's own new Diffuse material. But I get an error when I try to run this test.
using UnityEngine;
using System.Collections;
using Holoville.HOTween;
using Holoville.HOTween.Plugins;
public class HoTweenColorTest : MonoBehaviour {
public Material _Material;
void OnGUI()
{
if (GUI.Button( new Rect(100f, 100f, 100f, 100f), "Start Color Lerp"))
{
HOTween.To(_Material, 1f, new TweenParms()
.Prop("color", new PlugSetColor(Color.red)));
}
}
}
Comment
Answer by Jessespike · Jun 13, 2014 at 07:10 PM
I found a solution that works for me. Hope it helps anyone that runs into the same issue. I created another script that gets/sets the material's color.
//MaterialController.cs
using UnityEngine;
using System.Collections;
public class MaterialController : MonoBehaviour {
public Color MainColor {
get { return this.renderer.material.color; }
set { this.renderer.material.color = new Color(value.r, value.g, value.b, value.a); }
}
}
//Updated HoTweenColorTest.cs
public MaterialController _MaterialController;
public Material _DefaultMaterial, _NextMaterial;
void OnGUI()
{
if (GUI.Button( new Rect(100f, 100f, 100f, 100f), "Start Color Lerp"))
{
HOTween.To( _MaterialController, 1f, new TweenParms()
.Prop( "MainColor", _NextMaterial.GetColor("_Color") )
);
}
}
Answer by lucianv · Sep 02, 2015 at 02:09 PM
@Jessespike Looking at hotween's documentation, a property can be defined like this:
HOTween.To(_Material, 1f, new TweenParms().Prop("color", new PlugSetColor(Color.red).Property("_Color")));
It worked for me.
Your answer