Ejemplo n.º 1
0
 void LateUpdate()
 {
     if (!playerActive)
     {
         return;
     }
     if (InputDB.GetButtonDown("Fire1") && canKickback)
     {
         canKickback = false;
     }
     else if (InputDB.GetButtonUp("Fire1"))
     {
         canKickback = true;
         gameObject.BroadcastMessage("ReleaseFire", 1, SendMessageOptions.DontRequireReceiver);
     }
     if (weapons[selectedWeapon] != null)
     {
         if (/*!InputDB.GetButton ("Fire1") || */ Time.time > weapons[selectedWeapon].GetComponent <GunScript>().nextFireTime)
         {
             BroadcastMessage("Cooldown");
         }
     }
     if (InputDB.GetButtonUp("Aim"))
     {
         gameObject.SendMessageUpwards("ReleaseFire", 2, SendMessageOptions.DontRequireReceiver);
     }
 }
Ejemplo n.º 2
0
        void Update()
        {
            if (paused)
            {
                movement.velocity = Vector3.zero;
                return;
            }

            if ((inputMoveDirection.x != 0 || inputMoveDirection.y != 0 || inputMoveDirection.z != 0) && grounded && PlayerWeapons.canMove)
            {
                if (!walking)
                {
                    BroadcastMessage("Walking", SendMessageOptions.DontRequireReceiver);
                }
                walking = true;
            }
            else
            {
                if (walking)
                {
                    BroadcastMessage("StopWalking", SendMessageOptions.DontRequireReceiver);
                }
                walking = false;
            }

            if (!useFixedUpdate)
            {
                UpdateFunction();
            }

            /*if(weaponCamera.transform.localPosition.y > standardCamHeight){
             *      weaponCamera.transform.localPosition.y = standardCamHeight;
             * } else if(weaponCamera.transform.localPosition.y < crouchingCamHeight){
             *      weaponCamera.transform.localPosition.y = crouchingCamHeight;
             * }*/

            if (grounded)
            {
                if (InputDB.GetButtonUp("Crouch") && PlayerWeapons.canCrouch)
                {
                    if (!proneFrame)
                    {
                        if (!crouching && !prone)
                        {
                            /*if(PlayerWeapons.sprinting && movement.useDive && !diving){
                             *      SetVelocity(transform.forward*25 + Vector3.up*12);
                             *      audio.volume = jumpSoundVolume;
                             *      audio.PlayOneShot(jumpSound);
                             *      diving = true;
                             *      lastCamSpeed = camSpeed;
                             *      crouching = false;
                             *      Prone();
                             *      camSpeed = 1;
                             *      movement.crouchedTime = -1;
                             *      //prone = true;
                             * } else {*/

                            Crouch();
                        }
                        else if (crouching && AboveIsClear())
                        {
                            crouching     = false;
                            stopCrouching = true;
                            NormalSpeed();
                        }
                        else if (prone && AboveIsClearProne())
                        {
                            //crouching = false;
                            //stopProne = true;
                            prone = false;
                            Crouch();
                        }
                    }
                    proneFrame = false;
                }
                else if (InputDB.GetButton("Crouch"))
                {
                    if (movement.crouchedTime < 0)
                    {
                        movement.crouchedTime = Time.time;
                    }
                    if (Time.time > movement.crouchedTime + movement.proneHoldTime && movement.crouchedTime > 0 && !prone)
                    {
                        if (useProne)
                        {
                            Prone();
                            proneFrame = true;
                        }
                        movement.crouchedTime = -1;
                    }
                }
                else
                {
                    movement.crouchedTime = -1;
                }
            }
            Vector3 weaponCameraLocalPos = weaponCamera.transform.localPosition;

            if (crouching && !prone)
            {
                if (weaponCameraLocalPos.y > crouchingCamHeight)
                {
                    weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y - crouchDeltaHeight * Time.deltaTime * camSpeed, crouchingCamHeight, standardCamHeight);
                }
                else
                {
                    weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y + crouchDeltaHeight * Time.deltaTime * camSpeed, proneCamHeight, crouchingCamHeight);
                }
            }
            else if (prone)
            {
                if (weaponCameraLocalPos.y > proneCamHeight)
                {
                    weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y - crouchDeltaHeight * Time.deltaTime * camSpeed, proneCamHeight, weaponCameraLocalPos.y);
                }
                else if (!hitProne)
                {
                    GunLook.jostleAmt = new Vector3(-.075f, -.12f, 0);
                    CamSway.jostleAmt = new Vector3(-.01f, -.03f, 0);
                    hitProne          = true;
                    GetComponent <AudioSource>().volume = proneLandSoundVolume;
                    GetComponent <AudioSource>().PlayOneShot(proneLandSound);
                }
            }
            else
            {
                if (weaponCameraLocalPos.y < standardCamHeight)
                {
                    weaponCameraLocalPos.y = Mathf.Clamp(weaponCameraLocalPos.y + standardCamHeight * Time.deltaTime * camSpeed, proneCamHeight, standardCamHeight);
                }
            }
            weaponCamera.transform.localPosition = weaponCameraLocalPos;
        }