Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by phissm ( 6 years ago )
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode()]
public class ProgressBar : MonoBehaviour
{

//    private int maximum;
//    private int current;
    public Image mask;
    private float timeLeft;
    private float timeTotal;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        timeLeft -= Time.deltaTime;
        GetCurrentFill;

        if (timeLeft < 0)
        {
            //return here?
        }
    }

    void GetCurrentFill()
    {
        float fillAmount = timeLeft / timeTotal;
        mask.fillAmount = fillAmount;
    }

    public bool doAction(float time_for_action) //  e.g float timeLeft = 30.0f;
    {
        timeLeft = time_for_action;
        timeTotal = time_for_action;
        return(true);


    }
}

 

Revise this Paste

Your Name: Code Language: