AnimationStepSync

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: Category: Animation Category: MonoBehaviour Category: CSharp Author: Lasse Järvensivu (Statement) ==Description== This script allows animations to move the object to a new loc...)
 
m (Changes category "CSharp" into "C Sharp")
Line 1: Line 1:
 
[[Category: Animation]]
 
[[Category: Animation]]
 
[[Category: MonoBehaviour]]
 
[[Category: MonoBehaviour]]
[[Category: CSharp]]
+
[[Category: C Sharp]]
 
Author: Lasse Järvensivu (Statement)
 
Author: Lasse Järvensivu (Statement)
 
==Description==
 
==Description==

Revision as of 20:37, 16 April 2011

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