void Update() { Vector3 temp = Input.mousePosition; temp.z = -_camera.transform.position.z; _orientation = _camera.ScreenToWorldPoint(temp); _orientation = _orientation - _parent.position; if (Time.time <= _timeWhenShoot + 0.02f) { RecoilMovement(); } if (_orientation.x < 0 && _orientation.y < transform.localPosition.y) { _direction = (_camera.ScreenToWorldPoint(temp) - transform.position).normalized; } else { _direction = (_camera.ScreenToWorldPoint(temp) - transform.position + _recoilOffsetLerped).normalized; } float tempAngle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg; if (_orientation.x < 0) { GameState._isCharacterFlipped = true; _parent.transform.localScale = new Vector3(-1, 1, 1); if (_shootFX != null) { _shootFXTransform.localEulerAngles = new Vector3(0, 180, 0); } if (_orientation.y < transform.localPosition.y) { transform.eulerAngles = new Vector3(0, 0, (Mathf.Clamp(tempAngle, -180, -180 + _aimAngleRange / 2)) - 180); } else { transform.eulerAngles = new Vector3(0, 0, Mathf.Clamp(tempAngle, 180 - _aimAngleRange / 2, 180) - 180); } } else { GameState._isCharacterFlipped = false; if (_shootFX != null) { _shootFXTransform.localEulerAngles = new Vector3(0, 0, 0); } _parent.transform.localScale = new Vector3(1, 1, 1); transform.eulerAngles = new Vector3(0, 0, Mathf.Clamp(tempAngle, -_aimAngleRange / 2, _aimAngleRange / 2)); } if (Input.GetKey(KeyCode.Mouse1)) { if (_magazineCapacity > 0) { _canShoot = true; } if (_pointLightStruct.Length > 0) { for (int i = 0; i < _pointLightStruct.Length; i++) { _toAdd = (_pointLightStruct[i]._maxLightAngle - _pointLightStruct[i]._minLightAngle) * Time.deltaTime; _pointLightStruct[i]._light.pointLightInnerAngle = Mathf.Clamp(_pointLightStruct[i]._light.pointLightInnerAngle -= _toAdd, _pointLightStruct[i]._minLightAngle, _pointLightStruct[i]._maxLightAngle); float tempRadius = Mathf.InverseLerp(_pointLightStruct[i]._minLightAngle, _pointLightStruct[i]._maxLightAngle, _pointLightStruct[i]._light.pointLightInnerAngle); _pointLightStruct[i]._light.pointLightInnerRadius = Mathf.Lerp(_pointLightStruct[i]._maxDistance, _pointLightStruct[i]._minDistance, tempRadius); } _spreadAngle = _pointLightStruct[0]._light.pointLightInnerAngle; } } else { if (_pointLightStruct.Length > 0) { for (int i = 0; i < _pointLightStruct.Length; i++) { _toAdd = (_pointLightStruct[i]._maxLightAngle - _pointLightStruct[i]._minLightAngle) * Time.deltaTime; _pointLightStruct[i]._light.pointLightInnerAngle = Mathf.Clamp(_pointLightStruct[i]._light.pointLightInnerAngle += _toAdd / 3, _pointLightStruct[i]._minLightAngle, _pointLightStruct[i]._maxLightAngle); float tempRadius = Mathf.InverseLerp(_pointLightStruct[i]._minLightAngle, _pointLightStruct[i]._maxLightAngle, _pointLightStruct[i]._light.pointLightInnerAngle); _pointLightStruct[i]._light.pointLightInnerRadius = Mathf.Lerp(_pointLightStruct[i]._maxDistance, _pointLightStruct[i]._minDistance, tempRadius); } _spreadAngle = _pointLightStruct[0]._light.pointLightInnerAngle; } if (_magazineCapacity <= 0) { _canShoot = false; } } if (Input.GetKeyDown(KeyCode.Mouse0) && _canShoot && _loaded) { float tempValue = Mathf.InverseLerp(_maxSpreadAngle, _minSpreadAngle, _spreadAngle); _playerEvent.PlayerShoot(new PlayerEvent.PlayerShootEventArgs { }); float tempMulti = Mathf.Lerp(.3f, 1f, tempValue); //StartCoroutine(ShootWithSpread(_spreadAngle, _pelletNumber, transform.rotation, _spawner.position, Mathf.Lerp(.3f,1f,tempValue))); if (tempMulti > .95f) { StartCoroutine(ShootWithSpread(0, _pelletNumber, transform.rotation, _spawner.position, tempMulti)); } else { StartCoroutine(ShootWithSpread(_spreadAngle, _pelletNumber, transform.rotation, _spawner.position, tempMulti)); } StartCoroutine(WaitBetweenShots()); _timeWhenShoot = Time.time + _timeToRecover; _magazineCapacity--; if (_magazineCapacity <= 0) { _playerEvent.PlayerReload(new PlayerEvent.PlayerReloadEventArgs { }); StartCoroutine(Reloading()); } if (_pointLightStruct.Length > 0) { for (int i = 0; i < _pointLightStruct.Length; i++) { _pointLightStruct[i]._light.pointLightInnerAngle = _pointLightStruct[i]._maxLightAngle; _pointLightStruct[i]._light.pointLightInnerRadius = _pointLightStruct[i]._minDistance; } } } if (Time.time < _timeWhenShoot) { SetIntensityPlayer(); } SetMagazineLight(); }