Skip to content

Instantly share code, notes, and snippets.

@kazuooooo
Created January 11, 2015 04:37
Show Gist options
  • Save kazuooooo/0faf2ab65407f03e026b to your computer and use it in GitHub Desktop.
Save kazuooooo/0faf2ab65407f03e026b to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class AnimationPra : MonoBehaviour {
// Use this for initialization
void Start () {
//AnimationClip:アニメーションの本体
//AnimationCurve:値変化のための曲線のグラフ
//Keyframe:○○が経過したときに、プロパティの値を○○にするということを指定したのがキーフレーム
//AnimationClipの作成
AnimationClip clip = new AnimationClip();
//AnimationCurveの作成
//AnimationCurve.Linear(開始時間,開始値,終了時間,終了値);
//この場合0秒で3fから開始して3f秒で3fに戻って終了するの意味
AnimationCurve curve = AnimationCurve.Linear(0f,3f,3f,3f);
//Keyframeの作成
//new Keyframe(アニメーションの経過時間,設定する値);
///1.5f秒後に7fの地点にいる
Keyframe key = new Keyframe(1.5f,7f);
//作成したKeyframeをcurveに組み込む
curve.AddKey(key);
//作成したcurveをclipに組み込む
//clip.SetCurve(パスの指定,タイプ,操作項目名,<<AnimationCurve>>);
clip.SetCurve ("", typeof(Transform), "localPosition.z", curve);
//wrapModeの設定
clip.wrapMode = WrapMode.Loop;
//animationにclipを組み込み
animation.AddClip (clip, "clip1");
//animationを再生
animation.Play ("clip1");
//なので関係としてはanimation have clip have curve have keyの状態ってこと
}
// Update is called once per frame
void Update () {
transform.Rotate (1f, 1f, 1f);
if (Input.GetKeyUp(KeyCode.Space)) {
animation.Play("clip1");
}
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