現在制作しているゲームでカウントダウンを使用しているのですが、技を選択した後にカウントダウンが始まる様にしていて
合計四回技を選択する場面があります。
一回目は普通にカウントダウンが始まるのですが、二回目以降がカウントダウンが始まらないので複数回カウントダウンを
使えるようにしたいです。
public class CountDownScript : MonoBehaviour
{
'[SerializeField] GameObject CountObj;'
'public Text Text;'
'public float totalTime;'
'int seconds;'
'public float timer = 5.0f;'
'bool enter = false;//Enterキーが押されたときのフラグ'
'[SerializeField] GameObject Player;'
'PlayerMoob py;'
'int count;'
'public void setCount(int a) { count = a; }'
void Start() { 'enter = false;' 'Player = GameObject.Find("Player");' 'py = Player.GetComponent<PlayerMoob>();' 'count = 1;' 'CountObj = GameObject.Find("CountObj");' } // Update is called once per frame void Update() { 'START();' 'if (enter == true)' '{ 'totalTime -= Time.deltaTime;' 'seconds = (int)totalTime;' 'Text.text = seconds.ToString();' 'CountObj.SetActive(true);' '//マイナス値にならないように' 'totalTime = Mathf.Max(totalTime, 1);' 'if (totalTime == 1)' '{ 'Text.text = "GO!!";' 'py.setMoob(1);' 'Invoke("FALSE",0.7f);' }' }' 'enter = false;' } void START() { ' if (count == 0) '{ 'enter = true;' }' }' void FALSE() '{ 'CountObj.SetActive(false);' 'totalTime = 4;' 'START();' }'
}'
上記はカウントダウンに用いるスクリプトです。
CountObjには適用しています。
上記の変数の値は0でカウントダウンが始まり、1でカウントダウンの表示をoffにしています。
1から0に変更などはできています。
public class FlipScript : MonoBehaviour
{
'[SerializeField] GameObject Scoreboard;'
'ScoreManager smr;'
'[SerializeField] GameObject CountObj;' 'CountDownScript cds;' '[SerializeField] GameObject Flip;' '[SerializeField] GameObject FenderGulub;' '[SerializeField] GameObject KyanKyan;'
'[SerializeField] GameObject NomalStopLine;'
'FrontStopLineScript fsls;'
// Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } void FlipButton() { 'smr = Scoreboard.GetComponent<ScoreManager>();' 'smr.setWaza(2);' 'cds = CountObj.GetComponent<CountDownScript>();' 'cds.setCount(0);' 'flip();' 'Flip.SetActive(false);' 'FenderGulub.SetActive(false);' 'KyanKyan.SetActive(false);' } void flip() { 'fsls = NomalStopLine.GetComponent<FrontStopLineScript>();' 'fsls.setCom(2);' }
}
上記のスクリプトはボタンをEnterキーを押して選択する技のスクリプトです。
setCount(0)がカウントダウンに使う変数の値です。
回答1件
あなたの回答
tips
プレビュー