5.4用代码控制改变状态机状态参数

2017-05-04  本文已影响48人  胤醚貔貅

usingUnityEngine;

usingSystem.Collections;

publicclassPlayerScript:MonoBehaviour{

privateAnimatoranimator;

privateintwalk;

voidStart(){

//获取animator组件,使用该组件来控制动画状态

animator=GetComponent<Animator>( );

//转换为hash值,效率更高

walk=Animator.StringToHash("Walk");

}

voidUpdate(){

//从其他状态到walk状态

if(Input.GetKeyDown(KeyCode.W)){

//设置walk动画参数的值为1

animator.SetInteger(walk,1);

}

//从walk状态到run状态

if(Input.GetKeyDown(KeyCode.R)){

//设置walk动画参数的值为2

animator.SetInteger(walk,2);

}

//从idel状态到run状态

if(Input.GetKeyDown(KeyCode.P)){

//设置run动画参数的值为1

animator.SetInteger("Run",1);

}

//从walk状态到idel状态

if(Input.GetKeyDown(KeyCode.I)){

//设置walk动画参数的值为0

animator.SetInteger(walk,0);

}

}

}

上一篇 下一篇

猜你喜欢

热点阅读