The docs for scripting key frames are vague. I need to understand how to set keys for curve properties. You would need to point the scripting to a property in a curve(like Material._Color.r) right?How do you pass them to a specific curve or animation file? (not sure how it works and it doesn't say.) Example: I want to set a key for the Material._Color.r but the docs don't show any property names being passed to, that I could find. Can this be done in the script? I'm trying to effect the time of the key and the value of the property if it matters. Thanks
material.Color.r is not a curve property, just a float value. You can sample a curve { someCurve.Evaluate(t) } to get a float value, then pass that into some other float property, but can not directly assign an animtionCurve to another property. Set new keys with addKey http://docs.unity3d.com/ScriptReference/AnimationCurve.AddKey.html or just Get, modify and Set them (ie you cannot modify them in-place with someCurve.keys[0] = xxx )
Thx for the reply hpjohn. Are you saying you cannot change the float value for Material._Color.r? I wanted to script a keyframe for it with one value and then another later, with a dif value. Not possible? I see some things are read only so wasn't sure.
You can change the color, sure. But you have to do it the long way Something like Code (CSharp): AnimationCurve curve float val = curve.Evaluate(time) Color col = material.color col.r = val material.color = col
Does curve.Evaluate(time) change float val incrementally and = to the amount of time that goes by? If so I think this is what I'm looking for. Rather than bother with the key frame scripting this may work for what I'm trying to do. I would set the value for the color.r and the rest to 0 to make the thing black (a quad used for a fade in out,) and change the color.a to = val and use if statements to control it. To reverse the fade for a fade in I would have to make a var that is subtracting time instead somehow. Does this make sense? Do you think it's the way to go about it?
If all you want is to fade something in or out, you don't need animationCurve at all. (unless you specifically want the fade to occur at a non-linear rate) Better to make a coroutine