usingUnityengine;usingSystem.Collections; Public classNewplayermove:monobehaviour {Private floatHor,ver; PrivateAnimator ANI; //Turn Speed Public floatTurnspeed =Ten; voidAwake () {ANI= getcomponent<animator> (); } voidUpdate () {Hor= Input.getaxis ("Horizontal"); Ver= Input.getaxis ("Vertical"); //MovingMove (ver); //Turn aroundTurn (Hor, ver); } voidMove (floatver) { if(Ver! =0|| Hor! =0) { //find the actual distance floatresult = MATHF.SQRT (Hor * hor + ver *ver); //setting the speed parameterAni. SetFloat (" Speed", Mathf.abs (result)); } Else { //let the character stop movingAni. SetFloat (" Speed", -1f); } } voidTurn (floatHorfloatver) { //If the player presses any one of the arrow keys if(Hor! =0|| Ver! =0) { //Get Direction vectorVector3 dir =NewVector3 (Hor,0, ver); //gets the four-dollar number represented by the direction vectorquaternion qua =quaternion.lookrotation (dir); //the player moves slowly to the rotation represented by the target four-dollar numberTransform.rotation =Quaternion.lerp (transform.rotation, qua, time.deltatime*turnspeed); } }}
Demo_ player movement (focus on animation settings)