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); } }