AnimationStepSync

From Unify Community Wiki
Revision as of 20:37, 16 April 2011 by Bunny83 (Talk | contribs)

Jump to: navigation, search

Author: Lasse Järvensivu (Statement)

Contents

Description

This script allows animations to move the object to a new location at the end of the animation.

This is useful if you perhaps have a jump animation, and want the character to end up standing where the character lands.

Usage

  • Attach script to object with animation.
  • Set which clips should sync upon completion by filling in the clips array.
  • Set reference to the object in your animation that the object should position itself at the end of the animation.

Notes

  • OnStepSync is called on the object when an animation ends and the object is repositioned.
  • This script isn't tested with live animation content, so it might not work well with blended animations.

C# - AnimationStepSync.cs

<csharp>using UnityEngine;

[RequireComponent(typeof(Animation))] public class AnimationStepSync : MonoBehaviour {

   public AnimationClip[] clips;
   public Transform reference;
   void Awake()
   {
       foreach (var clip in clips)
       {
           if (clip != null)
                AddStepSyncEvent(clip);
       }
   }
   void AddStepSyncEvent(AnimationClip clip)
   {
       var stepSyncEvent = new AnimationEvent();
       stepSyncEvent.time = clip.length;
       stepSyncEvent.functionName = "OnStepSync";
       clip.AddEvent(stepSyncEvent);
   }
   void OnStepSync()
   {
       transform.position = reference.position;
       transform.rotation = reference.rotation;
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox