Last active
August 29, 2015 13:57
-
-
Save Buravo46/9442992 to your computer and use it in GitHub Desktop.
【Unity】スクリプトで移動のアニメーションをする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CreateNewAnimationClipScript : MonoBehaviour { | |
public Vector3 addCurrentPosition; | |
void Start() { | |
CreateMoveAnimation(gameObject.transform.position, addCurrentPosition); | |
} | |
void CreateMoveAnimation(Vector3 currentPosition, Vector3 addCurrentPosition){ | |
// AnimationCurve : キーフレームを追加し、所定の時間に曲線を加え、アニメーションのスピードを変化させます。 | |
// Linear(startTime, startValue, endTime, endValue) : 時間と値の始めと終わりを設定する。直線の動き。 | |
AnimationCurve curveX = AnimationCurve.Linear(0, currentPosition.x, 10, currentPosition.x + addCurrentPosition.x); | |
AnimationCurve curveY = AnimationCurve.Linear(0, currentPosition.y, 10, currentPosition.y + addCurrentPosition.y); | |
AnimationCurve curveZ = AnimationCurve.Linear(0, currentPosition.z, 10, currentPosition.z + addCurrentPosition.z); | |
AnimationClip clip = new AnimationClip(); | |
clip.SetCurve("", typeof(Transform), "localPosition.x", curveX); | |
clip.SetCurve("", typeof(Transform), "localPosition.y", curveY); | |
clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ); | |
animation.AddClip(clip, "movePositionAnimation"); | |
animation.Play("movePositionAnimation"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment