//Разрушение астеройда от оружия 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(); }
private void HandleOnAsteroidDestroy(object sender, EventArgs e) { OnAsteroidDestroy?.Invoke(sender, e); }
private void OnDisable() { WaveManager.onAsteroidDestroy -= CheckAsteroids; }
private void OnEnable() { WaveManager.onAsteroidDestroy += CheckAsteroids; }