unity3d 人员控制代码
生活随笔
收集整理的這篇文章主要介紹了
unity3d 人员控制代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
普通瀏覽復制代碼
private?var?walkSpeed?:?float?=?1.0; private?var?gravity??=?100.0; private?var?moveDirection?:?Vector3?=?Vector3.zero; private?var?charController?:?CharacterController; function?Start() { ??charController?=?GetComponent(CharacterController); ??animation.wrapMode?=?WrapMode.Loop; } function?Update?()? { ??if(charController.isGrounded?==?true) ??{ ????if(Input.GetAxis("Vertical")?>?.1) ????{ ??????if(Input.GetButton("Run")) ??????{ ????????animation.CrossFade("run"); ????????walkSpeed?=?4; ??????} ??????else ??????{ ????????animation["walk"].speed?=?1; ????????animation.CrossFade("walk"); ????????walkSpeed?=?1; ??????} ????} ????else?if(Input.GetAxis("Vertical")?<?-.1) ????{ ??????animation["walk"].speed?=?-1; ??????animation.CrossFade("walk"); ??????walkSpeed?=?1; ????} ????else ????{ ??????animation.CrossFade("idle"); ????} ???? ????//?Create?an?animation?cycle?for?when?the?character?is?turning?on?the?spot ????if(Input.GetAxis("Horizontal")?&&?!Input.GetAxis("Vertical")) ????{ ??????animation.CrossFade("walk"); ????} ???? ???? ????transform.eulerAngles.y?+=?Input.GetAxis("Horizontal"); ????//?Calculate?the?movement?direction?(forward?motion) ????moveDirection?=?Vector3(0,0,?Input.GetAxis("Vertical")); ????moveDirection?=?transform.TransformDirection(moveDirection); ?????? ??} ?? ??moveDirection.y?-=?gravity?*?Time.deltaTime; ??charController.Move(moveDirection?*?(Time.deltaTime?*?walkSpeed)); }
總結
以上是生活随笔為你收集整理的unity3d 人员控制代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity3D 场景与C# Contro
- 下一篇: 最新 Unity3D鼠标滑轮控制物体放大