using System; using System.Collections; using System.Collections.Generic; using DG.Tweening; using UnityEngine; using Random = UnityEngine.Random; namespace RND { public class ScreenCoins : MonoBehaviour { private LootMoney[] _coins = new LootMoney[0]; [CustomButton("Init")] public void TestInit() { Init(15); } public void Init(int count) { _coins = CreateCoins(count); } private LootMoney[] CreateCoins(int count) { var coinPrefab = Assets.Load("UI/Coin"); var coins = new LootMoney[count]; Camera mainCamera = CameraManager.Main; for (var i = 0; i < count; i++) { coins[i] = Assets.Create(coinPrefab); coins[i].transform.SetParent(mainCamera.transform); coins[i].gameObject.SetLayerRecursive(LayerMask.NameToLayer("UI_FX")); coins[i].Init(LootMoney.MoveTarget.COUNTER, SyncCoinsTextType.SAVE, autoMove: false); Vector3 randomOffset = Random.insideUnitSphere * 1f; randomOffset.z = 4f; coins[i].transform.localPosition = Vector3.forward * 4f; coins[i].transform.localScale = Vector3.one; coins[i].transform.DOLocalMove(randomOffset, 0.5f).SetEase(Ease.OutCubic); //Sound.Play("CoinsFly"); } return coins; } [CustomButton("MoveCoins")] public void TestMoveCoins() { StartCoroutine(MoveCoins()); } public IEnumerator MoveCoins() { for (int i = 0; i < _coins.Length; i++) { _coins[i].MoveToTarget(); int randomFrameDelay = Random.Range(1, 5); for (int j = 0; j < randomFrameDelay; j++) yield return null; } } private void OnDisable() { if (_coins.Length == 0) return; foreach (LootMoney coin in _coins) { if (coin != null) Destroy(coin.gameObject); } _coins = new LootMoney[0]; } } }