Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Stat : MonoBehaviour {
  7.  
  8. private Image content;
  9.  
  10. [SerializeField]
  11. private float lerpspeed;
  12.  
  13. private float currentFill;
  14.  
  15. public float MyMaxValue { get; set; }
  16.  
  17. private float currentValue;
  18.  
  19. public float MyCurrentValue
  20. {
  21. get
  22. {
  23. return currentValue;
  24. }
  25.  
  26. set
  27. {
  28. if (value > MyMaxValue)
  29. {
  30. currentValue = MyMaxValue;
  31. }
  32. else if (value < 0)
  33. {
  34. currentValue = 0;
  35. }
  36. else
  37. {
  38. currentValue = value;
  39. }
  40.  
  41. currentFill = currentFill / MyCurrentValue;
  42. }
  43.  
  44.  
  45. }
  46.  
  47.  
  48. // Use this for initialization
  49. void Start ()
  50. {
  51. content = GetComponent<Image>();
  52. }
  53.  
  54. // Update is called once per frame
  55. void Update ()
  56. {
  57.  
  58. if (currentFill != content.fillAmount)
  59. {
  60. content.fillAmount = Mathf.Lerp(content.fillAmount, currentFill, Time.deltaTime * lerpspeed);
  61. }
  62. }
  63.  
  64. public void Initialize(float currentValue, float maxValue)
  65. {
  66. MyMaxValue = maxValue;
  67. MyCurrentValue = currentValue;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement