private void explode() { if (_hasExploded || !_isActivated) { return; } ThirdPersonCamera.Shake(transform.position, ShakeIntensity, ShakeDuration); _hasExploded = true; if (Explosion != null) { var alert = Explosion.GetComponent <Alert>(); if (alert != null) { alert.Generator = _attacker; } var particle = GameObject.Instantiate(Explosion, transform.position, Quaternion.identity, null); particle.SetActive(true); } var colliders = Physics.OverlapSphere(transform.position, ExplosionRadius); var count = Physics.OverlapSphereNonAlloc(transform.position, ExplosionRadius, Util.Colliders); for (int i = 0; i < count; i++) { var collider = Util.Colliders[i]; if (!collider.isTrigger) { var part = collider.GetComponent <BodyPartHealth>(); if (part == null) { var closest = collider.transform.position; if (collider.GetType() == typeof(MeshCollider)) { if (((MeshCollider)collider).convex) { closest = collider.ClosestPoint(transform.position); } } var vector = transform.position - closest; var distance = vector.magnitude; if (distance < ExplosionRadius) { Vector3 normal; if (distance > float.Epsilon) { normal = vector / distance; } else { normal = (closest - collider.transform.position).normalized; } Apply(collider.gameObject, closest, normal, (1 - distance / ExplosionRadius)); } } } } GameObject.Destroy(gameObject); }
protected virtual void Frame() { _hasJustFired = false; if (_isGoingToFire) { _isFiringOnNextUpdate = true; } if (_hitWait >= 0) { _hitWait -= Time.deltaTime; } if (DebugAim) { Debug.DrawLine(Origin, Origin + (RaycastTarget - Origin).normalized * Distance, Color.red); if (_isUsingCustomRaycast) { Debug.DrawLine(_customRaycastOrigin, _customRaycastTarget, Color.green); } } // Notify character if the trigger is pressed. Used to make faces. { var isAllowedAndFiring = _isGoingToFire && _isAllowed; if (Character != null) { if (isAllowedAndFiring && !_wasAllowedAndFiring) { Character.NotifyStartGunFire(); if (FireStarted != null) { FireStarted.Invoke(); } } if (!isAllowedAndFiring && _wasAllowedAndFiring) { Character.NotifyStopGunFire(); if (FireStopped != null) { FireStopped.Invoke(); } } } _wasAllowedAndFiring = isAllowedAndFiring; } _fireWait -= Time.deltaTime; // Check if the trigger is pressed. if (_isFiringOnNextUpdate && _isAllowed) { // Time in seconds between bullets. var fireDelay = 1.0f / Rate; var delay = 0f; // Fire all bullets in this frame. while (_fireWait < 0) { var hasFired = false; for (int i = 0; i < BulletsPerShot; i++) { if (LoadedBulletsLeft <= 0) { break; } if (fire(delay, !ConsumeSingleBulletPerShot)) { hasFired = true; } } if (hasFired && ConsumeSingleBulletPerShot) { Consume(); } if (hasFired) { for (int i = 0; i < _listeners.Length; i++) { _listeners[i].OnFire(delay); } if (Fired != null) { Fired.Invoke(); } if (Character != null) { if (PumpAfterFire) { Character.InputPump(0.1f); } Character.InputRecoil(Recoil.Vertical, Recoil.Horizontal); ThirdPersonCamera.Shake(Character, Recoil.ShakeIntensity, Recoil.ShakeTime); } } else { for (int i = 0; i < _listeners.Length; i++) { _listeners[i].OnEmptyFire(); } if (EmptyFire != null) { EmptyFire.Invoke(); } } delay += fireDelay; _fireWait += fireDelay; _isGoingToFire = false; } } _isFiringOnNextUpdate = false; _isUsingCustomRaycast = false; // Clamp fire delay timer. if (_fireWait < 0) { _fireWait = 0; } if (_laser != null && Character != null) { _laser.Alpha = Character.IsZooming ? 1 : 0; } adjustLaser(); _additionalError = 0; _errorMultiplier = 1; }