コード例 #1
0
ファイル: TNTPig.cs プロジェクト: GrayRose1982/marioNew
    private IEnumerator Explosive(float time)
    {
        // Prepare explosive
        Skeleton.loop          = true;
        Skeleton.AnimationName = EnemyAnimationName.Attack;
        IsAlive = false;
        yield return(new WaitForSeconds(time));

        // Explosive
        RaycastHit2D[] hits = Physics2D.CircleCastAll(Collider.bounds.center, _radiusExplosive, Vector2.zero);
        foreach (var hit in hits)
        {
            if (hit.transform.CompareTag(ObjectTag.Player) || hit.transform.CompareTag(ObjectTag.Enemy))
            {
                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                if (character != null)
                {
                    character.Attacked(AttackType.Hit);
                }
            }
            else if (hit.transform.CompareTag(ObjectTag.TileBlock))
            {
                IGoreable g = hit.transform.GetComponent <IGoreable>();
                if (g != null)
                {
                    g.Gore();
                }
            }
        }

        Destroy();
    }
コード例 #2
0
ファイル: HelmetChicken.cs プロジェクト: dqtoy/marioNew
    /// <summary>
    /// Create damage when role
    /// </summary>
    protected void RoleDamage()
    {
        Vector2 size     = Collider.bounds.size;
        Vector2 position = Collider.bounds.center;

        size.y     *= .2f;
        size.x     *= .8f;
        position.x += IsRight ? size.x / 4 : -size.x / 4;
        RaycastHit2D[] hits = Physics2D.BoxCastAll(position, size, 0, Vector2.zero);

        bool changeDirection = false;

        foreach (var hit in hits)
        {
            if (hit.transform.CompareTag(ObjectTag.Player))
            {
                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                character.Attacked(AttackType.Reflect, this);
            }
            else if (hit.transform.CompareTag(ObjectTag.Enemy))
            {
                if (hit.transform.name == Trans.name)
                {
                    continue;
                }

                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                character.Attacked(AttackType.Reflect);
            }
            else if (hit.transform.CompareTag(ObjectTag.TileBlock))
            {
                changeDirection = true;
                IGoreable tile = hit.transform.GetComponent <IGoreable>();
                tile.Gore();
            }
            else if (hit.transform.CompareTag(ObjectTag.Ground))
            {
                changeDirection = true;
            }
        }

        if (changeDirection)
        {
            IsRight = !IsRight;
        }
    }