using UnityEngine; public static class FieldCleaner { const string SORTLAYER_BACKGROUND = "Background"; const float EXPLOSION_FORCE = 30; static readonly Vector3 EXPLOSION_ORIGIN = new Vector3(0, -2, -5); const float EXPLOSION_RADIUS = 50; const float TIME_TO_DESTROY = 5; static Transform[,] field; //передаем переходим мы в меню или нет. Если нет, то переход отсюда в новый раунд //Надо еще сделать в конструкторе чтобы nextState указывать а то ж непонятно вообще public static void Clear() { field = GameManager.instance.chipTransforms; SoundManager.instance.playExplosion(); if (GameManager.instance.currentChip != null) { Object.Destroy(GameManager.instance.currentChip); } GameManager.fieldModel.makeEmptyField(width: GameManager.instance.Cols, height: GameManager.instance.Rows); GameManager.instance.chipTransforms = new Transform[GameManager.instance.Rows, GameManager.instance.Cols]; Explode(); } private static void Explode() { for (int i = 0; i < GameManager.instance.Rows; i++) { for (int j = 0; j < GameManager.instance.Cols; j++) { Transform chipTransform = field[i, j]; if (chipTransform != null) { Rigidbody rb = chipTransform.GetComponent(); rb.isKinematic = false; rb.AddExplosionForce(EXPLOSION_FORCE, EXPLOSION_ORIGIN, EXPLOSION_RADIUS, upwardsModifier: 1, ForceMode.Impulse); chipTransform.GetComponent().sortingLayerName = SORTLAYER_BACKGROUND; chipTransform.GetChild(0).GetComponent().sortingLayerName = SORTLAYER_BACKGROUND; Object.Destroy(chipTransform.gameObject, TIME_TO_DESTROY + Random.Range(-1f, 1f));//чтобы уничтожались не одновременно } } } } }