// ========== 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); } }
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); }
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); } }
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); }