Animation.CrossFade 淡入淡出
function CrossFade (animation : string, fadeLength : float = 0.3F, mode : PlayMode = PlayMode.StopSameLayer) : void
Description描述
Fades the animation with name animation in over a period of time seconds and fades other animations out.
在一定时间内淡入名称为name的动画并且淡出其他动画。
if mode is PlayMode.StopSameLayer, animations in the same layer as animation will be faded out while animation is faded in. if mode is PlayMode.StopAll, all animations will be faded out while animation is faded in.
如果模式是PlayMode.StopSameLayer,在同一层的动画将在动画淡入的时候淡出。如果模式是PlayMode.StopAll,所有动画将在淡入的时候淡出。
If the animation is not set to be looping it will be stopped and rewinded after playing.
如果动画没有被设置成循环,它将停止并且在播放完成之后倒带至开始。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
animation.CrossFade("Walk", 0.2F);
}
}
// Fade the walk cycle in and fade all other animations in the same layer out.
// 淡入walk循环并且淡出同一层的所有其他动画。
// Complete the fade within 0.2 seconds.
// 在0.2秒之内完成淡入淡出。
animation.CrossFade("Walk", 0.2);
另一个例子:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1F)
animation.CrossFade("Run");
else
animation.CrossFade("Idle");
}
}
// Makes a character contains a Run and Idle animation
// fade between them when the player wants to move
// 让一个角色包含Run和Idle动画,并且在玩家想移动的时候在他们之间淡入淡出。
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("Run");
else
animation.CrossFade("Idle");
}
最后修改:2011年1月12日 Wednesday 23:15