コード例 #1
0
ファイル: IceBomb.cs プロジェクト: Unknownow/item-shooter
    // ========== Private methods ==========
    private void IncreaseRadiusUpdate()
    {
        if (_currentRadius >= radius)
        {
            return;
        }

        _currentRadius += Time.deltaTime * _currentRadiusIncreaseSpeed;

        Collider2D[] affectedColliders = Physics2D.OverlapCircleAll(transform.position, _currentRadius, _affectedLayer);
        foreach (Collider2D collider in affectedColliders)
        {
            SpriteRenderer renderer = collider.GetComponent <SpriteRenderer>();
            if (renderer == null)
            {
                continue;
            }
            if (!ObjectUtils.CheckIfSpriteAppearInScreen(renderer))
            {
                continue;
            }

            IShootableObject affectedObject = collider.GetComponent <IShootableObject>();
            affectedObject.OnAffectedByEffectObject(type, gameObject);
        }
    }
コード例 #2
0
    protected void OnHitShootableObject(GameObject shootableObject)
    {
        SpriteRenderer renderer = shootableObject.gameObject.GetComponent <SpriteRenderer>();

        if (renderer == null || !ObjectUtils.CheckIfSpriteAppearInScreen(renderer))
        {
            return;
        }

        ShootableObjectCollision shootableObjectCollision = shootableObject.GetComponent <ShootableObjectCollision>();

        shootableObjectCollision.OnGetHitByBullet(gameObject);
        gameObject.GetComponent <Bullet>().OnHitShootableObject(shootableObject);
        // gameObject.SetActive(false);
    }
コード例 #3
0
    private void OnDetonate()
    {
        Collider2D[] affectedColliders = Physics2D.OverlapCircleAll(transform.position, ((BombConfig)config).RADIUS, _affectedLayer);
        foreach (Collider2D collider in affectedColliders)
        {
            SpriteRenderer renderer = collider.GetComponent <SpriteRenderer>();
            if (renderer == null)
            {
                continue;
            }
            if (!ObjectUtils.CheckIfSpriteAppearInScreen(renderer))
            {
                continue;
            }

            IShootableObject affectedObject = collider.GetComponent <IShootableObject>();
            affectedObject.OnAffectedByEffectObject(type, gameObject);
        }
    }
コード例 #4
0
    private GameObject GetAffectedObject(GameObject sourceObject = null)
    {
        if (sourceObject == null)
        {
            return(null);
        }
        Collider2D[] affectedColliders = Physics2D.OverlapCircleAll(sourceObject.transform.position, ((LightningBallConfig)config).RADIUS, _affectedLayer);
        GameObject   affectedObject    = null;

        if (affectedColliders.Length >= 0)
        {
            float minDistance = ((LightningBallConfig)config).RADIUS + 1;
            ArrayUtils.Shuffle(affectedColliders);
            foreach (Collider2D collider in affectedColliders)
            {
                SpriteRenderer renderer = collider.GetComponent <SpriteRenderer>();
                // if (_affectedGameObject.Contains(collider.gameObject) || renderer == null || collider.GetComponent<IShootableObject>() == null)
                if (_affectedGameObject.Contains(collider.gameObject) || renderer == null || !ObjectUtils.CheckIfSpriteAppearInScreen(renderer) || collider.GetComponent <IShootableObject>() == null)
                {
                    continue;
                }

                float distance = Vector3.Distance(sourceObject.transform.position, collider.transform.position);
                if (distance < minDistance)
                {
                    affectedObject = collider.gameObject;
                    minDistance    = distance;
                }
            }
        }
        return(affectedObject);
    }