Hi!
I have a script which create an animation at runtime from an array of coordinates.
Now i want to add some events at specific keyframes positions of this animation clip.
here is the script for adding the events:
private var myEvent : AnimationEvent;
private var e : int=0; // place of the event in events[]
function AddEventToMyAnimation() {
myEvent = new AnimationEvent();
myEvent.functionName="myEventFunction";
// I set keys for each animation frame
// so the variable t represents the current frame position on my animation.
for (var t : int=0; t<animationDataArray.Length; t++) {
if (iWantAnEvent==true) {
myAnimationClip.AddEvent(myEvent);
myAnimationClip.events[e].time=t;
e+=1;
}
else {
}
}
}
function myEventFunction () {
print("Nice job event added");
}
I definitely have a problem with the line:
myAnimationClip.AddEvent(myEvent);
This line seems to crash Unity (close itself) when the script executes at runtime…
Since there’s not a lot of documentation about scripting animation events, I guess I’m doing something wrong. Unless it’s a real Unity bug issue!?
(docs : http://docs.unity3d.com/ScriptReference/AnimationClip.AddEvent.html)