Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Stat : MonoBehaviour {
- private Image content;
- [SerializeField]
- private float lerpspeed;
- private float currentFill;
- public float MyMaxValue { get; set; }
- private float currentValue;
- public float MyCurrentValue
- {
- get
- {
- return currentValue;
- }
- set
- {
- if (value > MyMaxValue)
- {
- currentValue = MyMaxValue;
- }
- else if (value < 0)
- {
- currentValue = 0;
- }
- else
- {
- currentValue = value;
- }
- currentFill = currentFill / MyCurrentValue;
- }
- }
- // Use this for initialization
- void Start ()
- {
- content = GetComponent<Image>();
- }
- // Update is called once per frame
- void Update ()
- {
- if (currentFill != content.fillAmount)
- {
- content.fillAmount = Mathf.Lerp(content.fillAmount, currentFill, Time.deltaTime * lerpspeed);
- }
- }
- public void Initialize(float currentValue, float maxValue)
- {
- MyMaxValue = maxValue;
- MyCurrentValue = currentValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement