美文网首页
5.4用代码控制改变状态机状态参数

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

作者: 胤醚貔貅 | 来源:发表于2017-05-04 16:34 被阅读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);

    }

    }

    }

    相关文章

      网友评论

          本文标题:5.4用代码控制改变状态机状态参数

          本文链接:https://www.haomeiwen.com/subject/bshdtxtx.html