- Home /
how to add cycle offset to animation using script
I'm new in unity. Recently, I am working on a project that we need to use cycle offset as the extrapolation between given animation curve. For now, I already performed an animation I need in loop mode. But when the animation ends, it will go back to the beginning position. So I need the cycle offset to keep it moving.`empty.AddComponent(); Animation anim = empty.GetComponent(); AnimationCurve curve;
// create a new AnimationClip
AnimationClip clip = new AnimationClip();
clip.legacy = true;
// create a curve to move the GameObject and assign to the clip
Keyframe[] keys;
keys = new Keyframe[2];
keys[0] = new Keyframe(0.0f, 0.0f);
keys[1] = new Keyframe(1.0f, 1.5f);
curve = new AnimationCurve(keys);
clip.SetCurve("", typeof(Transform), "localPosition.z", curve);
clip.wrapMode = WrapMode.Loop;
anim.AddClip(clip, clip.name);
anim.Play(clip.name);`
empty is the name of gameobject I want to move.
Answer by Koyemsi · Oct 28, 2018 at 01:15 PM
This may help :
https://answers.unity.com/questions/1241153/using-cycle-offset-feature-inside-of-animator.html
Your answer
Follow this Question
Related Questions
League of legends-Dota Style moving and animating script 0 Answers
Play either the first or second animation on an object without specifying its name 1 Answer
,Capture user input as per animation state and then play animations accordingly 0 Answers
character lean/look 0 Answers
How do I start an animation at a particular point when I am using a list of prefabs? 0 Answers