You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using uc;
public class GameTimer : MonoBehaviour {
[SerializeField]
private TimerActivity timerActivity;
private float TimerDuration;
public Image TimerImage;
public Gradient gradient;
private float timer;
[SerializeField]
private bool isFilled;
[SerializeField]
float _prograss;
public float Prograss { get { if (isFilled) return _prograss; else return 1 - _prograss; } }
// Use this for initialization
void Start () {
}
void OnEnable()
{
timer = 0;
TimerDuration = timerActivity.timerDuration;
_prograss = 0;
//SetPrograss();
}
// Update is called once per frame
void Update () {
SetPrograss();
}
void SetPrograss()
{
timer += Time.deltaTime;
_prograss = Mathf.Clamp(timer / TimerDuration, 0, 1);
Color currentColor = gradient.Evaluate(_prograss);
TimerImage.color = currentColor;
if (isFilled)
TimerImage.fillAmount = _prograss;
else
TimerImage.fillAmount = 1 - _prograss;
}
}