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

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);

}

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容