void Update()
    {
        // PROCESS INTERACTIVE OBJECTS
        // Is the crosshair over a usuable item or descriptive item...first get ray from centre of screen
        var ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

        // Cast Ray and collect ALL hits
        var hits = Physics.RaycastAll(ray, 5, _interactiveMask | _backpackMask);

        // Process the hits for the one with the highest priority
        if (hits.Length > 0)
        {
            // Used to record the index of the highest priority
            int             highestPriority = int.MinValue;
            InteractiveItem priorityObject  = null;

            // Iterate through each hit
            foreach (var hit in hits)
            {
                // Fetch its InteractiveItem script from the database
                InteractiveItem interactiveObject = _gameSceneManager.GetInteractiveItem(hit.collider.GetInstanceID());

                // If this is the highest priority object so far then remember it
                if (interactiveObject != null && interactiveObject.Priority > highestPriority)
                {
                    priorityObject  = interactiveObject;
                    highestPriority = priorityObject.Priority;
                }
            }

            if (priorityObject != null)
            {
                if (priorityObject.activationType == ActivationType.MouseButtonPressed && Input.GetMouseButton(0) ||
                    priorityObject.activationType == ActivationType.MouseButtonDown && Input.GetMouseButtonDown(0))
                {
                    priorityObject.Drag(this);
                }
            }
        }

        if (SelectedDraggableItem != null)
        {
            SelectedDraggableItem.Drag(this);
            if (Input.GetMouseButtonUp(0))
            {
                SelectedDraggableItem.Drop();
                SelectedDraggableItem = null;
            }
        }

        if (SelectedStorageItem != null && Input.GetMouseButtonUp(0))
        {
            SelectedStorageItem.Drop();
            SelectedStorageItem = null;
        }
    }
    void Update()
    {
        Ray        ray;
        RaycastHit hit;

        RaycastHit[] hits;

        //Process interactive objects
        //is the crosshair over a useable item or a descriptive item? first get ray from centre of screen
        ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

        //calculate ray length
        float rayLength = Mathf.Lerp(1.0f, 1.8f, Mathf.Abs(Vector3.Dot(_camera.transform.forward, Vector3.up)));

        //cast ray and collect all hits
        hits = Physics.RaycastAll(ray, rayLength, _interactiveMask);

        //process the hits for the one with the highest priority
        if (hits.Length > 0)
        {
            //used to record index of the highest priority
            int             highestPriority = int.MinValue;
            InteractiveItem priorityObject  = null;

            //Iteracte through each hit
            for (int i = 0; i < hits.Length; i++)
            {
                //process next hit
                hit = hits[i];

                //fetch its interactiveitem sscript from the database
                InteractiveItem interactiveObject = _gameSceneManager.GetInteractiveItem(hit.collider.GetInstanceID());

                //if this is the highest priority object so far then remember it
                if (interactiveObject != null && interactiveObject.priority > highestPriority)
                {
                    priorityObject  = interactiveObject;
                    highestPriority = priorityObject.priority;
                }
            }

            //if we found an object then display its text and process any possible activation
            if (priorityObject != null)
            {
                if (_playerHUD)
                {
                    _playerHUD.SetInteractionText(priorityObject.GetText());
                }
                if (Input.GetButtonDown("Use"))
                {
                    priorityObject.Activate(this);
                }
            }
        }
        else
        {
            if (_playerHUD)
            {
                _playerHUD.SetInteractionText(null);
            }
        }

        //are we attacking?!
        if (Input.GetMouseButtonDown(0) && _ammo > 0)
        {
            if (_ammo >= 0)
            {
                _ammo -= 1;
                _shootSound.Play();
                DoDamage();
            }
            //_shootSound.Play();
            //DoDamage();
        }
        if (Input.GetMouseButtonDown(0) && _ammo <= 0)
        {
            _emptyGun.Play();
        }
        if (Input.GetKeyDown("r") && _ammo <= 5 && _ammo >= 0)
        {
            _reloadGun.Play();
            _ammo = _maxAmmo;
            print("Bullets currently: " + _ammo);
        }

        if (_fpsController && _soundEmitter != null)
        {
            //Bloodradius = zombies can smell player when low health!
            float newRadius = Mathf.Max(_walkRadius, (100.0f - _health) / _bloodRadiusScale);
            switch (_fpsController.movementStatus)
            {
            case PlayerMoveStatus.Landing: newRadius = Mathf.Max(newRadius, _landingRadius); break;

            case PlayerMoveStatus.Running: newRadius = Mathf.Max(newRadius, _runRadius); break;
            }
            _soundEmitter.SetRadius(newRadius);

            _fpsController.dragMultiplierLimit = Mathf.Max(_health / 100.0f, 0.25f);
        }
        Debug.Log("" + _ammo);
        if (_playerHUD)
        {
            _playerHUD.Invalidate(this);
        }
    }
    void Update()
    {
        if (Input.GetButtonDown("Inventory") && _inventoryUI != null)
        {
            if (!_inventoryUI.activeSelf)
            {
                _inventoryUI.SetActive(true);
                if (_playerHUD)
                {
                    _playerHUD.gameObject.SetActive(false);
                }

                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
                return;
            }
            else
            {
                _inventoryUI.SetActive(false);
                if (_playerHUD)
                {
                    _playerHUD.gameObject.SetActive(true);
                }

                Cursor.visible   = false;
                Cursor.lockState = CursorLockMode.Locked;
            }
        }

        Ray        ray;
        RaycastHit hit;

        RaycastHit[] hits;

        ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2));
        float rayLength = Mathf.Lerp(1, 1.8f, Mathf.Abs(Vector3.Dot(_camera.transform.forward, Vector3.up)));

        hits = Physics.RaycastAll(ray, rayLength, _interactiveMask);

        if (hits.Length > 0)
        {
            int             highestPriority = int.MinValue;
            InteractiveItem priorityObject  = null;

            for (int i = 0; i < hits.Length; i++)
            {
                hit = hits[i];

                InteractiveItem interactiveObject = _gameSceneManager.GetInteractiveItem(hit.collider.GetInstanceID());
                if (interactiveObject != null && interactiveObject.priority > highestPriority)
                {
                    priorityObject  = interactiveObject;
                    highestPriority = interactiveObject.priority;
                }
            }

            if (priorityObject != null)
            {
                if (_playerHUD)
                {
                    if (_interactionString)
                    {
                        _interactionString.value = priorityObject.GetText();
                    }
                }

                if (Input.GetButtonDown("Use"))
                {
                    priorityObject.Activate(this);
                }
            }
        }
        else
        {
            if (_interactionString)
            {
                _interactionString.value = null;
            }
        }

        if (Input.GetMouseButtonDown(0) && Time.time > _nextAttackTime)
        {
            DoDamage();
        }

        if (_fbsController)
        {
            float newRadius = Mathf.Max(_walkRadius, (100 - _health.value) / _bloodRadiusScale);
            switch (_fbsController.movementStatus)
            {
            case PlayerMoveStatus.Landing:
                // We don't want to emit any sound at the start of the game
                if (Time.time > 2f)
                {
                    newRadius = Mathf.Max(newRadius, _landingRadius);
                }
                break;

            case PlayerMoveStatus.Running:
                newRadius = Mathf.Max(newRadius, _runRadius);
                break;

            default:
                break;
            }

            _soundEmitter.SetRadius(newRadius);

            _fbsController.dragMultiplierLimit = Mathf.Max(_health.value / 100, .25f);
        }

        if (Input.GetMouseButtonDown(1))
        {
            DoTaunt();
        }
    }
Beispiel #4
0
    void Update()
    {
        Ray        ray;
        RaycastHit hit;

        RaycastHit [] hits;

        // PROCESS INTERACTIVE OBJECTS
        // Is the crosshair over a usuable item or descriptive item...first get ray from centre of screen
        ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

        // Calculate Ray Length
        float rayLength = Mathf.Lerp(1.0f, 1.8f, Mathf.Abs(Vector3.Dot(_camera.transform.forward, Vector3.up)));

        // Cast Ray and collect ALL hits
        hits = Physics.RaycastAll(ray, rayLength, _interactiveMask);

        // Process the hits for the one with the highest priorty
        if (hits.Length > 0)
        {
            // Used to record the index of the highest priorty
            int             highestPriority = int.MinValue;
            InteractiveItem priorityObject  = null;

            // Iterate through each hit
            for (int i = 0; i < hits.Length; i++)
            {
                // Process next hit
                hit = hits[i];

                // Fetch its InteractiveItem script from the database
                InteractiveItem interactiveObject = _gameSceneManager.GetInteractiveItem(hit.collider.GetInstanceID());

                // If this is the highest priority object so far then remember it
                if (interactiveObject != null && interactiveObject.priority > highestPriority)
                {
                    priorityObject  = interactiveObject;
                    highestPriority = priorityObject.priority;
                }
            }

            // If we found an object then display its text and process any possible activation
            if (priorityObject != null)
            {
                if (_playerHUD)
                {
                    _playerHUD.SetInteractionText(priorityObject.GetText());
                }

                if (Input.GetButtonDown("Use"))
                {
                    priorityObject.Activate(this);
                }
            }
        }
        else
        {
            if (_playerHUD)
            {
                _playerHUD.SetInteractionText(null);
            }
        }

        // Are we attacking?
        if (Input.GetMouseButtonDown(0) && Time.time > _nextAttackTime)
        {
            DoDamage();
        }



        // Calculate the SoundEmitter radius and the Drag Multiplier Limit
        if (_fpsController && _soundEmitter != null)
        {
            float newRadius = Mathf.Max(_walkRadius, (100.0f - _health) / _bloodRadiusScale);
            switch (_fpsController.movementStatus)
            {
            case PlayerMoveStatus.Landing: newRadius = Mathf.Max(newRadius, _landingRadius); break;

            case PlayerMoveStatus.Running: newRadius = Mathf.Max(newRadius, _runRadius); break;
            }

            _soundEmitter.SetRadius(newRadius);

            _fpsController.dragMultiplierLimit = Mathf.Max(_health / 100.0f, 0.25f);
        }


        // Do Insult
        if (Input.GetMouseButtonDown(1))
        {
            DoTaunt();
        }


        // Update the Helath and Stamina on the Player HUD
        if (_playerHUD)
        {
            _playerHUD.Invalidate(this);
        }
    }