Когда нажата кнопка, выбирается случайный игровой объект и начинается анимация подарка, когда она заканчивается, она должна выглядеть так, как на картинке.Я хочу, чтобы мой случайный игровой объект появился в ??????когда анимация заканчивается.Проблема в том, что я не знаю как.Еще одна вещь, как блокировать кнопку до завершения анимации подарка, я хочу, чтобы за один раз открывалось только 1 ящик для лута.
изображение подарка
public class GiftValue
{
public int GValue;
public int GWeight;
public GiftValue(int gvalue, int gweight)
{
GValue = gvalue;
GWeight = gweight;
}
}
public List<GiftValue> GiftwithWeight = new List<GiftValue>
{
new GiftValue(1, 25),
new GiftValue(2, 25),
new GiftValue(3, 25),
new GiftValue(4, 20),
new GiftValue(5, 5),
};
private readonly List<int> _GiftList = new List<int>();
public Animator OpenGiftAnimation;
public Text txtSellGiftAmount;
private int GiftAmount=10;
private void Start()
{
foreach (GiftValue kvp in GiftwithWeight)
{
for (int i = 0; i < kvp.GWeight; i++)
{
_GiftList.Add(kvp.GValue);
}
}
}
public int GetRandomNumber()
{
// get a random inxed from 0 to 99
int randomIndex = Random.Range(0, _GiftList.Count);
// get the according value
return _GiftList[randomIndex];
}
public void OpenGiftBtn()
{
if(GiftAmount>0)
{
OpenGiftAnimation.Play("OpenAnimation", -1, 0f);
int itemGiftNumber = GetRandomNumber();
int itemGiftIndex = GiftwithWeight.FindIndex(w => w.GValue == itemGiftNumber);
GiftAmount--;
txtSellGiftAmount.text = GiftAmount.ToString();
Debug.Log($"The odds for this were {GiftwithWeight[itemGiftIndex].GWeight / 100f:P} !");
}
}