修改FPSWalker.js

替换说明:用FPSWalker.js替换掉Assets\Standard Assets\Scripts下的FPSWalker.js
主要功能:
1、新增"+"  "-"号控制行走的速度,"+"增加速度,"-"减慢速度
2、新增"["  "]"号控制视野范围。
3、"W":向前
   "S":向后
   "A":向左
   "D":向右
4、(   增加胶囊高度和半径
   )   减小胶囊高度和半径
View Code
复制代码
   
   
1 var speed = 6.0 ; 2 var jumpSpeed = 8.0 ; 3 var gravity = 20.0 ; 4 5 private var moveDirection = Vector3.zero; 6 private var grounded : boolean = false ; 7 8 function FixedUpdate() { 9 10 if (Input.GetKey(KeyCode.KeypadPlus) || Input.GetKey(KeyCode.Equals)) 11 { 12 speed += 0.05 ; 13 } 14 if (Input.GetKey(KeyCode.KeypadMinus) || Input.GetKey(KeyCode.Minus)) 15 { 16 if (speed > 0 ) 17 { 18 speed -= 0.05 ; 19 } 20 else 21 {speed = 0 ;} 22 } 23 24 if (grounded) { 25 // We are grounded, so recalculate movedirection directly from axes 26 moveDirection = new Vector3(Input.GetAxis( " Horizontal " ), 0 , Input.GetAxis( " Vertical " )); 27 moveDirection = transform.TransformDirection(moveDirection); 28 moveDirection *= speed; 29 30 if (Input.GetButton ( " Jump " )) { 31 moveDirection.y = jumpSpeed; 32 } 33 } 34 35 // Apply gravity 36 moveDirection.y -= gravity * Time.deltaTime; 37 38 // Move the controller 39 var controller : CharacterController = GetComponent(CharacterController); 40 var flags = controller.Move(moveDirection * Time.deltaTime); 41 grounded = (flags & CollisionFlags.CollidedBelow) != 0 ; 42 if (controller.height > 4 || controller.height < 1 ) { 43 controller.height = 2 ;controller.radius = 0.4 ; 44 } 45 if (controller.height >= 1 || controller.height <= 4 ){ 46 if (Input.GetKeyDown(KeyCode.Alpha9)) 47 { 48 controller.height -= 0.2 ; 49 controller.radius = controller.height * 0.2 ; 50 } 51 if (Input.GetKeyDown(KeyCode.Alpha0)) 52 { 53 controller.height += 0.2 ; 54 controller.radius = controller.height * 0.2 ; 55 } 56 } 57 58 var camera : Camera = GameObject.Find( " Main Camera " ).GetComponent(Camera); 59 if (Input.GetKey(KeyCode.RightBracket)){ 60 if (camera.fieldOfView < 90 ){ 61 camera.fieldOfView += 0.5 ; 62 } 63 } 64 if (Input.GetKey(KeyCode.LeftBracket)){ 65 if (camera.fieldOfView > 60 ){ 66 camera.fieldOfView -= 0.5 ; 67 } 68 else {camera.fieldOfView = 60 ;} 69 } 70 } 71 72 @script RequireComponent(CharacterController)
复制代码
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值