Unity3d progress bar

本文关键字:bar progress Unity3d | 更新日期: 2023-09-27 18:04:56

我正在使用unity3D开发一款游戏,我需要帮助制作进度时间条,以便在收集特定道具时添加时间,从而使游戏继续。

Unity3d progress bar

创建一个类型为填充的UI图像。根据进度条使用水平或垂直填充。然后在脚本中可以操作图像的值。我将给你一个非常简单的c#示例。剩下的你可以使用谷歌和阅读unity脚本API。

public class Example: MonoBehaviour {
    public Image progress;
    // Update is called once per frame
    void Update () 
    {
            progress.fillAmount -=  Time.deltaTime;
    }
}

您可以在slider.setvalue中使用滑块。

的例子:

//to use this add first a slider to your canvas in the editor.
public GameObject sliderObject; //attachs this to the slider gameobject in  the editor or use Gameobject.Find
Slider slider = sliderObject.GetComponent<Slider>();
float time;
float maxtime; //insert your maxium time
void start(){
    slider.maxValue = maxtime;
}
void update()
{
    time += Time.deltaTime;
    if (time < maxtime)
    {
        slider.value = time;
    }
    else
    {
        Destroy(sliderObject);
        //time is over, add here what you want to happen next
    }
}