インスペクタでのAnimationCurveの利用

インスペクタ上でAnimationCurveを使ったデータの利用。
グラフをいじって、Evaluate(float time)にて、timeに対する値が取得できる。
using UnityEngine;
using System.Collections;
/// <summary>
/// AnimationCurveのテスト。
/// </summary>
public class CurveTest : MonoBehaviour {
	/// <summary>
	/// AnimationCurve.
	/// </summary>
	[SerializeField]
	AnimationCurve curve;
	/// <summary>
	/// 経過時間。
	/// </summary>
	float passedTime = 0f;
	/// <summary>
	/// Update.
	/// </summary>
	void Update () {
		passedTime += Time.deltaTime;
		int sec = (int)passedTime;
		float per = passedTime - sec;
		Vector3 pos = this.transform.position;
		pos.x = this.curve.Evaluate(per);
		this.transform.position = pos;
	}
}
							
													
コメントを残す