using System; using System.Collections; using System.Collections.Generic; using DG.Tweening; using UnityEngine; using Random = UnityEngine.Random; public class ScreenCoins : MonoBehaviour { private LootCoin[] _coins = new LootCoin[0]; [CustomButton("Init")] public void TestInit() { Init(15); } public void Init(int count) { _coins = CreateCoins(count); } private LootCoin[] CreateCoins(int count) { var coinPrefab = Resources.Load("UI/Coin"); var coins = new LootCoin[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(LootCoin.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 (LootCoin coin in _coins) { if(coin != null) Destroy(coin.gameObject); } _coins = new LootCoin[0]; } }