c# - 我的礼物动画完成后如何添加随机游戏对象?
问题描述
按下按钮时,随机选择游戏对象并开始礼物动画,完成后它应该看起来像图像中的那个。我希望我的随机游戏对象出现在 ?????? 动画结束时。问题是我不知道怎么做。还有一件事,我如何阻止按钮直到礼物动画完成,我一次只希望打开 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} !");
}
}
解决方案
推荐阅读
- python - 合并 DataFrame 时丢失的条目数
- javascript - 如何访问 withStyle 组件内的 DOM 节点?
- python - 在 python 中为 Ising 模型嵌套 for 循环
- java - 有没有办法避免不同背景的重复 Cucumber 场景?
- javascript - 将我的 Chrome 扩展程序中的表单数据写入 Google 表格
- python - Pandas Dataframe 多索引
- scala - Scala 等价于 Java 的 Number 和 divide 方法
- kotlin - Kotlin DSL - 联合结构
- isabelle - 如何使用 fmmap_keys 定义函数的终止顺序?
- elasticsearch - 如何在 ES 6.4 中使用新的 Java Api 重新索引?