コード例 #1
0
 /// <summary>
 /// Initializes the object.
 /// </summary>
 protected virtual void Start()
 {
     _toughnessLeft      = _toughness;
     _hitTimer           = new Timer(_hitInterval, true);
     _destructible       = GetComponent <Destructible>();
     _defaultPosition    = transform.position;
     _availableByDefault = available;
     _defaultSpeed       = _speed;
 }
コード例 #2
0
        /// <summary>
        /// Deals damage to a destructible object.
        /// </summary>
        /// <param name="destructible">A destructible object<param>
        /// <returns>Was the object hit.</returns>
        private bool Hit(Destructible destructible)
        {
            if (destructible != null)
            {
                destructible.TakeDamage(damage);
                return(true);
            }

            return(false);
        }
コード例 #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);
            }
        }