Ejemplo n.º 1
0
    // Allows quitting by pressing ESC.
    void Update()
    {
        //The following code was taken from http://answers.unity3d.com/questions/784526/46-ugui-select-next-inputfield-with-entertab.html
        //and exists solely to allow tabbing between input fields on the title screen. Whew!
        if (InputWrapper.GetKeyDown(KeyCode.Tab))
        {
            Selectable  next        = null;
            Selectable  current     = null;
            EventSystem eventSystem = EventSystem.current;

            // Figure out if we have a valid current selected gameobject
            if (eventSystem.currentSelectedGameObject != null)
            {
                // Unity doesn't seem to "deselect" an object that is made inactive
                if (eventSystem.currentSelectedGameObject.activeInHierarchy)
                {
                    current = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();
                }
            }

            if (current != null)
            {
                // When SHIFT is held along with tab, go backwards instead of forwards
                if (InputWrapper.GetKey(KeyCode.LeftShift) || InputWrapper.GetKey(KeyCode.RightShift))
                {
                    next = current.FindSelectableOnLeft();
                    if (next == null)
                    {
                        next = current.FindSelectableOnUp();
                    }
                }
                else
                {
                    next = current.FindSelectableOnRight();
                    if (next == null)
                    {
                        next = current.FindSelectableOnDown();
                    }
                }
            }
            else
            {
                // If there is no current selected gameobject, select the first one
                if (Selectable.allSelectables.Count > 0)
                {
                    next = Selectable.allSelectables[0];
                }
            }

            if (next != null)
            {
                next.Select();
            }
        }
    }
Ejemplo n.º 2
0
 private void Update()
 {
     reloadTime += Time.deltaTime;
     if (reloadTime >= fireDelay)
     {
         if (InputWrapper.GetKeyDown(KeyCode.Space))
         {
             StartCoroutine(delay());
             reloadTime = 0;
         }
     }
 }
Ejemplo n.º 3
0
    public virtual void Update()
    {
        if (isLocalPlayer)
        {
            if (coolDownTimer >= 0)
            {
                coolDownTimer -= Time.deltaTime;
            }

            //the player has pressed the button identified by the weaponUseKey field
            //and the weapon is not on cooldown
            if (InputWrapper.GetKeyDown(weaponUseKey) || InputWrapper.GetMouseButtonDown(1))
            {
                //if enough ammo to use weapon, check for cooldown
                if (ammoCount >= ammoUsePerActivation)
                {
                    //if weapon not on cooldown, activate it and do cleanup
                    if (coolDownTimer <= 0)
                    {
                        //take ammo away from the player
                        ammoCount -= ammoUsePerActivation;

                        //restart the cooldown timer
                        coolDownTimer = coolDownTotalSeconds;

                        ActivateWeapon();

                        //if ammo is now zero, report the depletion
                        if (ammoCount == 0)
                        {
                            AmmoDepleted();
                        }
                    }
                    //if weapon is on cooldown, report activation while on cooldown
                    else
                    {
                        WeaponActivatedOnCooldown();
                    }
                }
                //if not enough ammo to use weapon, report activation while no ammo
                else
                {
                    WeaponActivatedNotEnoughAmmo();
                }
            }

            if (InputWrapper.GetKeyDown(addAmmoKey))
            {
                AddAmmo(1);
            }
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Have all of the keys been held down for a while?
 /// </summary>
 /// <returns></returns>
 public bool IsBeingRepeated()
 {
     if (!IsBeingPressed())
     {
         return(false);
     }
     if (HasAxis)
     {
         // always run axis commands as fast as possible
         return(false);
     }
     return(_keyPressDefinitions.Any((definition) => definition.All((c) => !InputWrapper.GetKeyDown(c))));
 }
Ejemplo n.º 5
0
    void Update()
    {
        blackScreen.SetActive(!splashVideo.isPlaying);

        if (InputWrapper.GetKeyDown(KeyCode.Escape))
        {
            StopCoroutine("ChangeSceneAfterTime");
            SceneManager.LoadScene(1);
        }

        if (splashVideo.isPlaying)
        {
            startedPlaying = true;
            return;
        }

        if (startedPlaying)
        {
            SceneManager.LoadScene(1);
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (currentInvincibleTimer > 0 && isServer)
        {
            currentInvincibleTimer -= Time.deltaTime;
        }
        //Death effects/respawn timer
        if (dead)
        {
            //Tilting animation
            if (tilting)
            {
                transform.Rotate(Vector3.right, -Time.deltaTime * sinkSpeed * 20);
                transform.position = transform.position + Vector3.up * (Time.deltaTime * sinkSpeed) / 10f;
                if (Mathf.Abs(transform.rotation.eulerAngles.x - 360) >= sinkAngle)
                {
                    GetComponent <Rigidbody>().useGravity = true;
                    tilting = false;
                }
            }

            //Respawn
            if (gameOver)
            {
                return;
            }
            respawnTimer += Time.deltaTime;
            if (respawnTimer > secondsToRespawn)
            {
                Respawn();
            }
        }

        //Hurt self functionality
        if (isLocalPlayer && InputWrapper.GetKeyDown(hurtSelfButton))
        {
            CmdHurtSelf(-5);
            return;
        }
    }
Ejemplo n.º 7
0
    // Update is called once per frame
    private void Update()
    {
        if (fps == false)
        {
            currentX += Input.GetAxis("Mouse X") * sensitivityX;
            currentY -= Input.GetAxis("Mouse Y") * sensitivityY;

            currentY = Mathf.Clamp(currentY, Y_angle_Min, Y_angle_Max);
        }
        else if (fps == true)
        {
            currentX += Input.GetAxis("Mouse X") * offsetX;
            currentY -= Input.GetAxis("Mouse Y") * offsetY;

            currentY = Mathf.Clamp(currentY, Y_angle_Min, Y_angle_Max);
        }

        //Tab Key allows to switch between first person and third person view
        if (InputWrapper.GetKeyDown(KeyCode.Tab))
        {
            if (fps == false)
            {
                fps          = true;
                Y_angle_Max  = 30.0f;
                sensitivityY = 2.0f * offsetY;
                distance     = 1.5f;
            }
            else
            {
                fps          = false;
                Y_angle_Max  = 25.0f;
                sensitivityY = 1.0f;
                distance     = 5.0f;
            }
        }
    }
Ejemplo n.º 8
0
    //used to gather input
    private void Update()
    {
        if (!boatToFollow)
        {
            Cursor.visible   = true;
            Cursor.lockState = CursorLockMode.Confined;
            return;
        }
        if (!gameIsPaused)
        {
            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Locked;
        }
        else
        {
            //else show cursor and unlck it
            Cursor.visible   = true;
            Cursor.lockState = CursorLockMode.None;
        }

        //if not doing a quickturn, do normal mouse based camera movement input
        if (!quickTurning)
        {
            //get and apply mouse movement input
            currentHorizontalRotation += Input.GetAxis("Mouse X") * horizontalSensitivity * (invertHorizontal ? -1 : 1);
            currentVerticalRotation   += Input.GetAxis("Mouse Y") * verticalSensitivity * (invertVertical ? -1 : 1);
            currentVerticalRotation    = Mathf.Clamp(currentVerticalRotation, minimumVerticalRotation, maximumVerticalRotation);

            //get and apply zoom input
            targetDistance -= Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity;
            targetDistance  = Mathf.Clamp(targetDistance, minimumZoomDistance, maximumZoomDistance);

            //since not turning, detect if should do a quickturn

            //quickturning to face the left was pressed
            if (InputWrapper.GetKeyDown(quickTurnLeft))
            {
                quickTurnTargetRotation   = currentHorizontalRotation - 90f;
                quickTurnStartingRotation = currentHorizontalRotation;
                quickTurning      = true;
                quickTurnProgress = 0;
            }
            //quickturning to face the right was pressed
            else if (InputWrapper.GetKeyDown(quickTurnRight))
            {
                quickTurnTargetRotation   = currentHorizontalRotation + 90f;
                quickTurnStartingRotation = currentHorizontalRotation;
                quickTurning      = true;
                quickTurnProgress = 0;
            }
        }
        //rotate toward the quickturn point
        else
        {
            quickTurnProgress        += Time.deltaTime / quickTurnTime;
            currentHorizontalRotation = Mathf.SmoothStep(quickTurnStartingRotation, quickTurnTargetRotation, quickTurnProgress);
            if (quickTurnProgress >= 1)
            {
                quickTurning = false;
            }
        }
    }