示例#1
0
 /// <summary>
 /// Do the actual hit.
 /// </summary>
 /// <param name="other">Other.</param>
 override protected bool DoHit(Collider2D other)
 {
     // Simple projectiles can hit only one thing
     if (!hasHitCharacter && enabled)
     {
         IHurtable hurtBox = (IHurtable)other.gameObject.GetComponent(typeof(IHurtable));
         // Got a hurt box and its not ourselves
         if (hurtBox != null && !hasHitCharacter && hurtBox.Mob != character)
         {
             if (projectile != null && destroyOnEnemyHit)
             {
                 projectile.DestroyProjectile(true);
             }
             damageInfo.Direction = transform.position - other.transform.position;
             hurtBox.Damage(damageInfo);
             if (!allowMultiHit)
             {
                 hasHitCharacter = true;
             }
             return(true);
         }
         else
         {
             if (projectile != null && destroyOnSceneryHit)
             {
                 projectile.DestroyProjectile(false);
             }
         }
     }
     return(false);
 }
        /// <summary>
        /// Do the actual hit.
        /// </summary>
        /// <param name="other">Other.</param>
        override protected bool DoHit(Collider2D other)
        {
            // Simple projectiles can hit only one thing
            if (!hasHitCharacter && enabled)
            {
                IHurtable hurtBox = (IHurtable)other.gameObject.GetComponent(typeof(IHurtable));
                // Got a hurt box and its not ourselves
                if (hurtBox != null && !hasHitCharacter && hurtBox.Mob != character)
                {
                    if (projectile != null && destroyOnEnemyHit)
                    {
                        projectile.DestroyProjectile(true);
                    }
                    damageInfo.Direction = transform.position - other.transform.position;
                    hurtBox.Damage(damageInfo);
                    if (!allowMultiHit)
                    {
                        hasHitCharacter = true;
                    }
                    if (character is Character)
                    {
                        ((Character)character).HitEnemy(hurtBox.Mob, damageInfo);
                    }
                    return(true);
                }
                else
                {
                    if (hurtBox == null && projectile != null && destroyOnSceneryHit)
                    {
                        projectile.DestroyProjectile(false);
                    }
                    // TODO: Ideally this shouldn't be here but on something related to grappling hook projectile
                    if (projectile is GrapplingHookProjectile)
                    {
                        if (((GrapplingHookProjectile)projectile).shouldParent)
                        {
                            projectile.gameObject.transform.parent = other.gameObject.transform;
#if UNITY_EDITOR
                            if (other.gameObject.transform.lossyScale != Vector3.one)
                            {
                                Debug.LogWarning("Grapple with shouldParent==true requires that all the colliders it collides with have a GameObject scale of (1,1,1) due to Unity bug with parenting to non-uniform colliders. Instead of scaling your game objects set the size on the collider and leave the scale at (1,1,1).");
                            }
#endif
                        }
                    }
                }
            }
            return(false);
        }