예제 #1
0
        /// <summary>
        /// Deals damage to a game character.
        /// </summary>
        /// <param name="character">A game character</param>
        /// <returns>Was the character hit.</returns>
        private bool Hit(GameCharacter character)
        {
            if (character != null && !character.IsDead)
            {
                character.TakeDamage(damage);
                return(true);
            }

            return(false);
        }
예제 #2
0
        private void OnCollisionEnter(Collision collision)
        {
            GameCharacter character = collision.gameObject.GetComponent <GameCharacter>();

            if (character != null)
            {
                if (!_touchedByOtherChar)
                {
                    _avoidOtherCharDir = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized;
                    _avoidOtherCharDir = _avoidOtherCharDir * Random.Range(0.7f, 1.3f);
                }

                _touchedByOtherChar = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Handles colliding with objects that can take damage.
        /// </summary>
        /// <param name="collision">The collision</param>
        private void OnCollisionEnter(Collision collision)
        {
            // Passes through invisible walls
            if (collision.gameObject.tag == InvisibleKey)
            {
                return;
            }

            // is something hit
            bool     hit               = false;
            bool     dontDestroy       = false;
            Collider immediateCollider = collision.contacts[0].otherCollider;

            if (_damageCharacters)
            {
                GameCharacter character = immediateCollider.
                                          transform.parent.GetComponent <GameCharacter>();
                //Shield shield = immediateCollider.transform.GetComponent<Shield>();

                if (character != null)              // && shield == null)
                {
                    dontDestroy = character.IsDead; // TODO: Replace with something better
                    hit         = Hit(character);
                }

                //Debug.Log("immediateCollider.gameObject: " + immediateCollider.gameObject.name);
            }

            if (!hit && _damageDestructibleObjects)
            {
                Destructible destructible = immediateCollider.gameObject.GetComponent <Destructible>();
                hit = Hit(destructible);
            }

            if (_deactivateOnCollision && !dontDestroy)
            {
                gameObject.SetActive(false);
            }
        }
예제 #4
0
        /// <summary>
        /// What happens when enemy hits a shield
        /// </summary>
        /// <param name="shield">shield script on the object that is hit</param>
        //protected virtual void HitShield(Shield shield)
        //{
        //    shield.Hit();
        //    HitType = HitCastType.SHIELD;
        //    Debug.Log("shield hit");
        //}

        /// <summary>
        /// What happens when enemy hits a character
        /// </summary>
        /// <param name="character">GameCharacter script on the object that is hit</param>
        protected virtual void HitCharacter(GameCharacter character)
        {
            character.TakeDamage(Damage);
            HitType = HitCastType.PLAYER;
            Debug.Log("character hit");
        }