unity3d - Unity - Button OnClick 仅在我单击另一个按钮后执行动画
问题描述
我有这 3 个按钮
当我按下点击按钮时,它会播放一个动画,并且可交互按钮设置为关闭一段时间,并显示“bt.interactable = false;”。在那个时间段之后,它被设置为 true。
在那之后它让我再次玩。
但是,动画的第二次播放仅在我再次播放“点击按钮”之前播放其他按钮之一时才有效。这是带有按钮计时器的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ldbutton : MonoBehaviour
{
public Image loading;
public Button bt;
int sec;
string pl1_name = "Unicorn";
public int counterclick;
bool buttonLocked;
Firebase_Bridge FB = new Firebase_Bridge();
int tmp_sec;
int totalSeconds = 0;
int TOTAL_SECONDS = 0;
async void Start()
{
if (bt.name.Equals("SpecialHitButton")){
string time = await FB.LoadData_player_timeplsuperhit(pl1_name);
sec = int.Parse(time);
}
if (bt.name.Equals("HitButton"))
{
string time = await FB.LoadData_player_timeplhit(pl1_name);
sec = int.Parse(time);
}
if (bt.name.Equals("DefendButton"))
{
string time = await FB.LoadData_player_timepldefend(pl1_name);
sec = int.Parse(time);
}
Debug.Log("star");
tmp_sec = sec;
bt.onClick.AddListener(() =>
{
loading.fillAmount = 1.0f;
bt.interactable = false;
if (counterclick < 2)
{
bt.interactable = false;
sec = tmp_sec;
if (sec > 0)
{
bt.interactable = false;
totalSeconds += sec;
}
TOTAL_SECONDS = totalSeconds;
StartCoroutine(second());
}
}
);
}
IEnumerator second()
{
bt.interactable = false;
Debug.Log("second");
yield return new WaitForSeconds(1f);
if (sec > 0)
{
sec--;
fillLoading();
StartCoroutine(second());
}
if (sec == 0)
{
counterclick = 0;
totalSeconds = 0;
TOTAL_SECONDS = 0;
//sec = 0;
StopCoroutine(second());
Debug.Log("termina");
yield return new WaitForSeconds(1f);
StartCoroutine(wait());
}
}
IEnumerator wait ()
{
bt.interactable = true;
bt.enabled=true;
return null;
}
void fillLoading()
{
Debug.Log("fillLoading");
totalSeconds--;
float fill = (float)totalSeconds / tmp_sec;
loading.fillAmount = fill;
Debug.Log("update");
}
}
有谁知道发生了什么?
解决方案
推荐阅读
- highcharts - Highcharts - 径向(或圆形)条形图 - 圆角/边框半径?
- python - 有没有一种方法可以将图像的像素值转换为 4D 数组(包括 1 个通道)而不是 Keras 的 3D 数组?
- spring-boot - SpringBootTest 上下文未加载?
- python - 为什么我的模型在 Google Colab 上训练时总是在 Keras Tensorflow 中返回 0 val loss?
- python - 刮掉搜索栏的价格 - 站点链接已更改
- python - 函数未通过所有行执行
- javascript - Yeoman 通过带有 args 的代码调用生成器
- python - 获取数据子集中(联合)最高的列名列表
- javascript - 多个套接字接收相同的随机生成的单词 - Node.js/Socket.io/Express.js
- machine-learning - 为什么higher需要深度复制基础模型的参数来创建功能模型?