【发布时间】:2015-09-03 11:36:06
【问题描述】:
所以我正在制作一款自上而下的坦克射击游戏,我想制作一个比以前更好的装填系统。所以我想到我需要一些进度条之王。我知道怎么做,所以我开始做。问题是它不能正常工作。正如我在上面的 .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 中
-
请澄清:alreadyReloading 和 needTimer 是公开的,它们是从场景中的任何其他对象调用的吗?另外,ammo 字段在哪里以及如何减少?如果减少 ammo 的时间与 Reload Update() 函数不同步,这可能是罪魁祸首。
-
这两个 bool 都没有在任何其他脚本中使用,我将它们设置为 public 以进行调试。您可以删除 public 并且什么都不会改变。弹药在其他脚本中被调用,称为射击,但只取值,以便于调用。 (如 value1 = ...GetComponent....value2;)。
-
Unity 编辑器中是否设置了 ammo 的初始值?
标签: c# user-interface unity3d progress-bar unity3d-gui