コード例 #1
0
        /// <summary>
        /// Applies damage to itself
        /// </summary>
        /// <param name="damage">Damage.</param>
        protected virtual void SelfDamage(int damage)
        {
            if (_health != null)
            {
                _health.Damage(damage, gameObject, 0f, DamageTakenInvincibilityDuration);
            }

            ApplyDamageTakenKnockback();
        }
コード例 #2
0
        /// <summary>
        /// Handles damage and the associated feedbacks
        /// </summary>
        protected virtual void HandleDamage()
        {
            if (_hitObject == null)
            {
                return;
            }

            WeaponHit();

            _health = _hitObject.MMGetComponentNoAlloc <Health>();

            if (_health == null)
            {
                // hit non damageable
                if (WeaponOnHitNonDamageableFeedback != null)
                {
                    WeaponOnHitNonDamageableFeedback.transform.position = _hitPoint;
                    WeaponOnHitNonDamageableFeedback.transform.LookAt(this.transform);
                }

                if (NonDamageableImpactParticles != null)
                {
                    NonDamageableImpactParticles.transform.position = _hitPoint;
                    NonDamageableImpactParticles.transform.LookAt(this.transform);
                    NonDamageableImpactParticles.Play();
                }

                WeaponHitNonDamageable();
            }
            else
            {
                // hit damageable
                _health.Damage(DamageCaused, this.gameObject, DamageCausedInvincibilityDuration, DamageCausedInvincibilityDuration);
                if (_health.CurrentHealth <= 0)
                {
                    WeaponKill();
                }

                if (WeaponOnHitDamageableFeedback != null)
                {
                    WeaponOnHitDamageableFeedback.transform.position = _hitPoint;
                    WeaponOnHitDamageableFeedback.transform.LookAt(this.transform);
                }

                if (DamageableImpactParticles != null)
                {
                    DamageableImpactParticles.transform.position = _hitPoint;
                    DamageableImpactParticles.transform.LookAt(this.transform);
                    DamageableImpactParticles.Play();
                }

                WeaponHitDamageable();
            }
        }
コード例 #3
0
ファイル: DamageOnTouch.cs プロジェクト: andres-03/01
        /// <summary>
        /// Describes what happens when colliding with a damageable object
        /// </summary>
        /// <param name="health">Health.</param>
        protected virtual void OnCollideWithDamageable(Health health)
        {
            // if what we're colliding with is a CorgiController, we apply a knockback force
            _colliderCorgiController = health.gameObject.MMGetComponentNoAlloc <CorgiController>();

            if ((_colliderCorgiController != null) && (DamageCausedKnockbackForce != Vector2.zero) && (!_colliderHealth.TemporaryInvulnerable) && (!_colliderHealth.Invulnerable) && (!_colliderHealth.ImmuneToKnockback))
            {
                _knockbackForce.x = DamageCausedKnockbackForce.x;
                if (DamageCausedKnockbackDirection == KnockbackDirections.BasedOnSpeed)
                {
                    Vector2 totalVelocity = _colliderCorgiController.Speed + _velocity;
                    _knockbackForce.x *= -1 * Mathf.Sign(totalVelocity.x);
                }
                if (DamagedTakenKnockbackDirection == KnockbackDirections.BasedOnOwnerPosition)
                {
                    if (Owner == null)
                    {
                        Owner = this.gameObject;
                    }
                    Vector2 relativePosition = _colliderCorgiController.transform.position - Owner.transform.position;
                    _knockbackForce.x *= Mathf.Sign(relativePosition.x);
                }

                _knockbackForce.y = DamageCausedKnockbackForce.y;

                if (DamageCausedKnockbackType == KnockbackStyles.SetForce)
                {
                    _colliderCorgiController.SetForce(_knockbackForce);
                }
                if (DamageCausedKnockbackType == KnockbackStyles.AddForce)
                {
                    _colliderCorgiController.AddForce(_knockbackForce);
                }
            }

            HitDamageableFeedback?.PlayFeedbacks(this.transform.position);

            if ((FreezeFramesOnHitDuration > 0) && (Time.timeScale > 0))
            {
                MMFreezeFrameEvent.Trigger(Mathf.Abs(FreezeFramesOnHitDuration));
            }

            // we apply the damage to the thing we've collided with
            _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration);
            SelfDamage(DamageTakenEveryTime + DamageTakenDamageable);
        }