- Home /
Animating Light Intensity with Animation Curve
Hi guys.
I am currently working on a small script to animate lights with a curve defined in a custom editor. I have checked that the curve being passed at runtime matches the curve defined in the editor and it does, however when I try to assign the curve to an animation clip I am recieving an error I cannot seem to resolve.
The error is:
Can't assign curve because the type does not inherit from Component. UnityEngine.AnimationClip:SetCurve(String, Type, String, AnimationCurve) LightingTrigger:Start() (at Assets/AbeHD Assets/Scripts/Lighting/LightingTrigger.cs:33)
and the code for my setup is:
using UnityEngine;
using System;
using System.Collections;
[Serializable]
[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(Animation))]
public class LightingTrigger : MonoBehaviour {
private BoxCollider m_cBoxCollider;
private Light m_cLight;
private Animation m_cAnimation;
private AnimationClip m_cIntensityClip;
public AnimationCurve m_cIntensityCurve;
private float m_fIntensity;
// Use this for initialization
void Start () {
m_cBoxCollider = GetComponent<BoxCollider>();
m_cBoxCollider.isTrigger = true;
m_cLight = GetComponent<Light>();
m_cAnimation = GetComponent<Animation>();
m_cIntensityClip = new AnimationClip();
m_cIntensityClip.SetCurve("", typeof(float), "light.intensity", m_cIntensityCurve);
m_cAnimation.AddClip(m_cIntensityClip, "Intensity");
m_cAnimation.Play("Intensity");
}
}
Any advice on what I am doing incorrectly would be very much appreciated!
Thanks.
Answer by Berenger · Jan 31, 2013 at 01:06 PM
I've never used it but, apparently, for the second parameter, you need the type of component that has a variable the name of the string in the third parameter. Try ...
m_cIntensityClip.SetCurve("", typeof(Light), "intensity", m_cIntensityCurve);
Your answer
Follow this Question
Related Questions
Animate mode does not contain definition for GetCurveBindings 2 Answers
Animation error message, can anyone explain? 1 Answer
The AnimationClip 'Running' used by the AnimationComponent 'corpse' must be marked as Legacy? 1 Answer
Mecanim errors after animation clip import 1 Answer
Only torso of sprite has weights 0 Answers