예제 #1
0
        private void ApplyDamage(GameObject otherObject)
        {
            if (waitList == null) waitList = new Dictionary<DamageReceiver, float>();

            // Check for shield first
            DamageShield shield = otherObject.GetComponentInChildren<DamageShield>();
            if (shield != null && shield.ShieldCollider.enabled)
            {
                if (shield.StatsSource != StatsSource)
                {
                    Destroy(gameObject);
                }
            }

            // Check for receiver
            DamageReceiver receiver = otherObject.GetComponentInChildren<DamageReceiver>();
            if (receiver != null)
            {
                // Check for self
                if (receiver.gameObject == gameObject) return;
                StatsCog statsCog = receiver.gameObject.GetComponent<StatsCog>();
                if (statsCog != null && statsCog == StatsSource) return;

                if (waitList.ContainsKey(receiver))
                {
                    if (Time.time >= waitList[receiver])
                    {
                        DealDamage(receiver);
                        waitList[receiver] = Time.time + minBetweenDamage;
                    }
                }
                else
                {
                    DealDamage(receiver);
                    waitList.Add(receiver, Time.time + minBetweenDamage);
                }
            }
        }
예제 #2
0
        //private void OnTriggerEnter(Collider other)
        //{
        //    ApplyDamage(other.gameObject);
        //}

        //private void OnColliderEnter(Collider other)
        //{
        //    ApplyDamage(other.gameObject);
        //}

        #endregion

        #region Public Methods

        public virtual void DealDamage(DamageReceiver receiver)
        {
            GameObject source = overrideDamageSource ? damageSource : gameObject;
            float applieDamage = receiver.TakeDamage(this, source);
            onDamageDealt?.Invoke(applieDamage, receiver);
        }
예제 #3
0
 private void DamageDealt(float amount, DamageReceiver target)
 {
     damageDealt = true;
 }