Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created January 11, 2015 05:00
Show Gist options
  • Save kazuooooo/c71d6623cb560b5b5b10 to your computer and use it in GitHub Desktop.
Save kazuooooo/c71d6623cb560b5b5b10 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class AnimationPra : MonoBehaviour {
// Use this for initialization
void Start () {
//1つめのアニメーションクリップ
AnimationClip clipA = new AnimationClip ();
AnimationCurve curveA = AnimationCurve.Linear (0f, 3f, 3f, 3f);
Keyframe keyA = new Keyframe (1.5f, 10f);
curveA.AddKey (keyA);
clipA.SetCurve ("", typeof(Transform), "localPosition.z", curveA);
clipA.wrapMode = WrapMode.Loop;
animation.AddClip (clipA, "anim1");
//2つめのアニメーションクリップ
AnimationClip clipB = new AnimationClip ();
AnimationCurve curveB = AnimationCurve.Linear (0f, 3f, 3f, 3f);
Keyframe key1 = new Keyframe (0.75f, 7f);
curveB.AddKey(key1);
Keyframe key2 = new Keyframe (1.5f, 3f);
curveB.AddKey(key2);
Keyframe key3 = new Keyframe (2.25f, 7f);
curveB.AddKey (key3);
clipB.SetCurve ("", typeof(Transform), "localPosition.z", curveB);
clipB.wrapMode = WrapMode.Loop;
animation.AddClip (clipB, "anim2");
animation.Play ("anim1");
}
// Update is called once per frame
void Update () {
transform.Rotate (1f, 1f, 1f);
if (Input.GetKeyDown(KeyCode.Space)) {
//<<Animation>>.IsPlaying(アニメーション名) 引数のアニメーションクリップが今再生中かどうかを取得
//(<<Animation>>.isPlaying:アニメーションが再生中かどうかを取得)
if(animation.IsPlaying("anim1")){
//<<Animation>>.PlayQueured(アニメーション名,<<QueueMode>>
//QueueMode: PlayNow ただちに再生
//CompleteOthers: 他のアニメーションが終了したら再生
//animation.PlayQueued("anim2",QueueMode.PlayNow);
animation.CrossFade ("anim2", 5.0f);
}else{
//animation.PlayQueued("anim1",QueueMode.PlayNow);
//<<Animation>>.CrossFade(アニメーション名,経過時間); 経過時間をかけてアニメーションを切り替える
animation.CrossFade ("anim1", 5.0f);
}
}
// if (Input.GetKeyDown (KeyCode.Space)) {
// animation.Stop();
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment