1.
usingUnityengine;usingSystem.Collections; Public classAnimatormove:monobehaviour { Public floatDirectiondamptime =. 25f; PrivateAnimator Animator;//declare an action machine variable animator voidStart () {animator= getcomponent<animator>(); } voidUpdate () {if(Animator = =NULL)return;//return will not perform the following actionsAnimatorstateinfo StateInfo= Animator. Getcurrentanimatorstateinfo (0);//determine if the animation is playing complete if(Stateinfo.isname ("Base Layer.run")) { if(Input.getbutton ("Fire1") ) animator. Setbool (" Jump",true); } Elseanimator. Setbool (" Jump",false); if(Input.getbuttondown ("Fire2") && Animator.layercount >=2) animator. Setbool ("Hi",true); Elseanimator. Setbool ("Hi",false); floatH = Input.getaxis ("Horizontal"); floatv = Input.getaxis ("Vertical"); Animator. SetFloat (" Speed", h * H + V *v); Animator. SetFloat ("Direction", H, Directiondamptime, time.deltatime); }}
2.
Private Animator Animator; void Start () { this. Getcomponent<animator>(); } void Update () { animatorstateinfo = animator. Getcurrentanimatorstateinfo (0); // Determine if the animation is playing complete if1.0f) { dosomething (); }}
Unity C # code sample