« 包含标签 key 的文章

keyframe control of 3D model Animation in Unity3D

Here’s a simple sample of controlling model animation in Unity3d.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using UnityEngine;
using System.Collections;
 
public class animationCtrl : MonoBehaviour {
	private float hSliderValue;
	private AnimationState currentAni;
 
	void Start () {
	    gameObject.animation.Play("shot");
	    gameObject.animation.Stop();
	    currentAni = animation["shot"];
	}
 
	void LateUpdate () {
	    currentAni.time = hSliderValue;
	    currentAni.enabled = true;
 
	    animation.Sample();
	    currentAni.enabled = false;
	}
 
	void OnGUI() {
	    hSliderValue = GUILayout.HorizontalSlider(hSliderValue, 0.0f, currentAni.length, GUILayout.Width(100));
	}
}