Ejemplo n.º 1
0
    //Разрушение астеройда от оружия
    private void Collapse()
    {
        if (_currentSize > 0)
        {
            SpawnNewAsteroids();
        }

        OnAsteroidDestroy?.Invoke(this, (int)_currentSize);

        // Создание информационного угасающего текста с количеством очков за уничтожение астероида

        _asteroidScore.SetScoreText(ScoreCounter.PointsBySize((int)_currentSize));
        Instantiate(_asteroidScorePrefab, transform.position, Quaternion.identity);

        Destroy(gameObject);
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        AudioManager.Instance.EffectsAudioSource.PlayOneShot(destroyAudioClip);

        if (shardPool != null)
        {
            OnAsteroidDestroy?.Invoke(shardsNumber);

            GameObject       shard;
            AsteroidBehavior shardAsteroidBehavior;

            // Random bias for asteroids shards make impossible to destroy all
            // newly spawned shards easily
            float randomCircleRadius = 2.5f;
            for (int i = 0; i < shardsNumber; i++)
            {
                shard = shardPool.GetObject();
                shard.transform.position = transform.position +
                                           (Vector3)(Random.insideUnitCircle * randomCircleRadius);

                shardAsteroidBehavior = shard.GetComponent <AsteroidBehavior>();
                if (shardAsteroidBehavior != null)
                {
                    shardAsteroidBehavior.AddRandomForceDirection();
                    shardAsteroidBehavior.OnAsteroidDestroy += this.OnAsteroidDestroy;
                }
                else
                {
                    Debug.LogWarning("Asteroid spawns shards without asteroid behavior component!");
                }
            }
        }
        else
        {
            OnAsteroidDestroy?.Invoke(0);
        }

        Hide();
    }
Ejemplo n.º 3
0
 private void HandleOnAsteroidDestroy(object sender, EventArgs e)
 {
     OnAsteroidDestroy?.Invoke(sender, e);
 }
Ejemplo n.º 4
0
 private void OnDisable()
 {
     WaveManager.onAsteroidDestroy -= CheckAsteroids;
 }
Ejemplo n.º 5
0
 private void OnEnable()
 {
     WaveManager.onAsteroidDestroy += CheckAsteroids;
 }