centner_dc

UI_Gradientbar

Oct 8th, 2020 (edited)
867
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using Extensions;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4.  
  5. namespace UI
  6. {
  7.     [RequireComponent(typeof(Image))]
  8.     public class Gradientbar : MonoBehaviour
  9.     {
  10.         [SerializeField] private Image _image;
  11.         [SerializeField] private Color[] _colors = {Color.white, Color.black};
  12.         [SerializeField] private FilterMode _filterMode;
  13.  
  14.         private GradientSprite _gradientSprite;
  15.  
  16.         void Awake()
  17.         {
  18.             _image = GetComponent<Image>();
  19.  
  20.             _gradientSprite = new GradientSprite(_colors, _filterMode);
  21.             _image.sprite = _gradientSprite.Sprite;
  22.         }
  23.     }
  24. }
RAW Paste Data