_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/MoneyAnimation.cs

107 lines
3.8 KiB
C#
Raw Normal View History

2024-11-13 21:45:48 +08:00
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class MoneyAnimation : MonoBehaviour
{
public Transform Parent; // <20><><EFBFBD>ø<EFBFBD><C3B8>ڵ㣬<DAB5><E3A3AC><EFBFBD>߲㼶<DFB2><E3BCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2B1BB><EFBFBD><EFBFBD>UI<55>ڵ<EFBFBD>
public GameObject coinPrefab; // <20><><EFBFBD>ҵ<EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
public Transform startPoint; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD><E3A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>λ<EFBFBD>ã<EFBFBD>
public Transform[] targetPoints; // Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3A8><EFBFBD><EFBFBD> 5 <20><>Ŀ<EFBFBD><C4BF><EFBFBD>
public int coinCount; // <20><><EFBFBD>ɵĽ<C9B5><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float spreadRadius; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɢ<EFBFBD>
public float moveDuration; // <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
public float delayBetweenCoins; // ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float randomTargetRadius; // ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD>ƫ<EFBFBD>Ƶİ뾶
private List<GameObject> coins = new List<GameObject>();
private void Start()
{
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
}
public void PlayCoinAnimation()
{
int completedCount = 0; // <20><>¼<EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// ȷ<><C8B7>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20><>Ԫ<EFBFBD><D4AA>
if (targetPoints.Length == 0)
{
Debug.LogError(<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>!");
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
for (int i = 0; i < coinCount; i++)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B8BD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD><EFBFBD>
Vector3 randomOffset = new Vector3(
Random.Range(-spreadRadius, spreadRadius),
Random.Range(-spreadRadius, spreadRadius),
0);
GameObject coin = Instantiate(coinPrefab, startPoint.position + randomOffset, Quaternion.identity, Parent);
coins.Add(coin);
}
// <20><><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD><D2B7>䵽Ŀ<E4B5BD><C4BF><EFBFBD>㣬ÿ<E3A3AC><C3BF>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
int coinsPerTarget = coinCount / targetPoints.Length;
List<List<GameObject>> groups = new List<List<GameObject>>();
// <20><><EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD><D2B7>䵽ÿ<E4B5BD><C3BF>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
int coinIndex = 0;
for (int i = 0; i < targetPoints.Length; i++)
{
List<GameObject> group = new List<GameObject>();
for (int j = 0; j < coinsPerTarget; j++)
{
if (coinIndex < coinCount)
{
group.Add(coins[coinIndex]);
coinIndex++;
}
}
groups.Add(group);
}
// <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
for (int i = 0; i < targetPoints.Length; i++)
{
Transform targetPoint = targetPoints[i];
List<GameObject> group = groups[i];
// Ϊÿ<CEAA><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int j = 0; j < group.Count; j++)
{
GameObject coin = group[j];
// <20><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><EFBFBD><E4A3AC>΢<EFBFBD><CEA2><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
float delay = j * delayBetweenCoins; // ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>ӳ<EFBFBD>
// <20><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><E3B8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Vector3 randomTargetPosition = targetPoint.position + new Vector3(
Random.Range(-randomTargetRadius, randomTargetRadius),
Random.Range(-randomTargetRadius, randomTargetRadius),
0);
// ʹ<><CAB9> DOTween <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><E3B8BD>
coin.transform.DOMove(randomTargetPosition, moveDuration)
.SetDelay(delay) // ֻ<><D6BB><EFBFBD>ӳ٣<D3B3><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ǰһ<C7B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
.SetEase(Ease.InOutQuad) // <20><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
.OnComplete(() =>
{
completedCount++;
Destroy(coin); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>ٽ<EFBFBD><D9BD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD>Ҷ<EFBFBD><D2B6><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>ʱ<EFBFBD><CAB1>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (completedCount == coinCount)
{
// <20><><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// BettingBtn.instance.GiveMoney();
}
});
}
}
}
}