C# 如何检查我的函数中的倒计时是否达到0? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 使用UnityEngine.UI; 公共枚举战国{开始,玩家回合,玩家回合,赢了,输了} 公共阶级斗争体系:单一行为 { 公共游戏对象播放器; 公共游戏对象播放器2prefab; 公共电视台; 公共转换播放器2台; 公共文本对话文本; 公共卫生与健康; 公共卫生玩家2健康; 公共战斗状态; 公共浮点数currentTime=0f; 浮动启动时间=15f; 公共文本倒计时文本; void Start() { state=BattleState.START; 开始例行程序(SetupBattle()); currentTime=启动时间; } void Update()//倒计时 { currentTime-=1*Time.deltaTime; countdownText.text=currentTime.ToString(“0”); 如果(currentTime
修改了Void Update()C# 如何检查我的函数中的倒计时是否达到0? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 使用UnityEngine.UI; 公共枚举战国{开始,玩家回合,玩家回合,赢了,输了} 公共阶级斗争体系:单一行为 { 公共游戏对象播放器; 公共游戏对象播放器2prefab; 公共电视台; 公共转换播放器2台; 公共文本对话文本; 公共卫生与健康; 公共卫生玩家2健康; 公共战斗状态; 公共浮点数currentTime=0f; 浮动启动时间=15f; 公共文本倒计时文本; void Start() { state=BattleState.START; 开始例行程序(SetupBattle()); currentTime=启动时间; } void Update()//倒计时 { currentTime-=1*Time.deltaTime; countdownText.text=currentTime.ToString(“0”); 如果(currentTime,c#,loops,unity3d,countdown,C#,Loops,Unity3d,Countdown,修改了Void Update() void Update()//倒计时 { currentTime-=1*Time.deltaTime; countdownText.text=currentTime.ToString(“0”); 如果(当前时间) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public enum BattleState
void Update()//倒计时
{
currentTime-=1*Time.deltaTime;
countdownText.text=currentTime.ToString(“0”);
如果(当前时间)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum BattleState { START, PLAYERTURN, PLAYER2TURN, WON, LOST }
public class BattleSystem : MonoBehaviour
{
public GameObject playerPrefab;
public GameObject player2Prefab;
public Transform playerBattleStation;
public Transform player2BattleStation;
public Text dialogueText;
public Health playerHealth;
public Health player2Health;
public BattleState state;
public float currentTime = 0f;
float startingTime = 15f;
public Text countdownText;
void Start()
{
state = BattleState.START;
StartCoroutine(SetupBattle());
currentTime = startingTime;
}
void Update() //countdown
{
currentTime -= 1 * Time.deltaTime;
countdownText.text = currentTime.ToString("0");
if (currentTime <= 0)
{
currentTime = 0;
Debug.Log("countdown hits 0");
}
}
IEnumerator SetupBattle()
{
dialogueText.text = "Get ready " + playerUnit.unitName + "!";
yield return new WaitForSeconds(5f);
state = BattleState.PLAYERTURN;
PlayerTurn(); //player 1's turn
}
void PlayerTurn()
{
dialogueText.text = playerUnit.unitName + "'s turn.";
}
}
void Update() //countdown
{
currentTime -= 1 * Time.deltaTime;
countdownText.text = currentTime.ToString("0");
if (currentTime <= 0 && state == BattleState.PLAYERTURN)
{
currentTime = 0;
playerHealth.numOfHearts = playerHealth.numOfHearts - 1;
state = BattleState.PLAYER2TURN;
Player2Turn();
currentTime = 10;
}
else if (currentTime <= 0 && state == BattleState.PLAYER2TURN)
{
currentTime = 0;
player2Health.numOfHearts = player2Health.numOfHearts - 1;
state = BattleState.PLAYERTURN;
PlayerTurn();
currentTime = 10;
}
}