zoukankan      html  css  js  c++  java
  • 修改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)
  • 相关阅读:
    数据库的接口
    BionicThe README from the bionic/libc
    发现问题——创新的原动力
    使用ADO或ADO控件访问数据库
    游标、事务并发和锁三者之间的那点事
    处女座——菜鸟程序员的工程总结
    数据库的基础知识以及创建数据库
    《Team Geek》前言(中文,自己翻译的)
    万里长征,始于足下——菜鸟程序员的学习总结(一)
    与RMAN相关的动态性能视图
  • 原文地址:https://www.cnblogs.com/Mygirl/p/2003133.html
Copyright © 2011-2022 走看看