所以我做一個自上而下的坦克射擊遊戲,我想做出比以前更好的重裝系統。所以我認識到我需要一些進度條的國王。我知道如何做到這一點,所以我開始這樣做。問題是它不能正常工作。正如我在上面的.gif中顯示的,當你第二次拍攝時,進度條不會下降。因爲我對團結感很陌生,所以我還是不太瞭解所有事情。所以我來到這裏,也許有人可以幫忙。
編輯: 我剛剛發現了另一個問題,也許一個答案,爲什麼我有這個問題。我的腳本試圖重新加載第二次,我的「needTimer」布爾是假的,因此進度條是不會下來的時候它是假的。新的問題將會是爲什麼它變得虛假而不是真實? 我重裝腳本:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Reload : MonoBehaviour {
public float ammo;
public Image progress;
public bool alreadyReloading;
public bool needTimer;
void Start() {
alreadyReloading = false;
}
IEnumerator needtimertime(){
yield return new WaitForSeconds (6.5f);
needTimer = false;
}
IEnumerator uztaisyt(){
Debug.Log ("REEELOUUUDING!");
yield return new WaitForSeconds(6.5f);
ammo += 1;
alreadyReloading = false;
}
void Update() {
if (needTimer == true) {
timer ("");
}
if (ammo < 5) {
if(alreadyReloading == false){
needTimer = true;
StartCoroutine(uztaisyt());
alreadyReloading = true;
}
}
if (progress.fillAmount <= 0) {
progress.fillAmount = 1.0f;
}
}
void timer(string tipas){
progress.fillAmount -= Time.deltaTime/6.5f;
StartCoroutine (needtimertime());
}
}
是什麼,當你試圖拍攝第二次彈藥變量的值? –
@Pawel Marecki 4,每次拍攝時都會下降。它顯示在gif – Justasmig
請澄清:_alreadyReloading_和_needTimer_是公開的,它們是否從場景中的任何其他對象被調用?另外,_ammo_字段在哪裏以及如何遞減?如果_ammo_遞減的時間與Reload Update()函數不同步,那可能是一個可能的罪魁禍首。 – BgRva