Last active
July 3, 2020 11:12
-
-
Save adamski11/22c34da5c4a5e71819c09ca91bab3a96 to your computer and use it in GitHub Desktop.
Add this script to any game object with an image component you're using as a fill bar colour the bar based on the current fill amount and a gradient set by you. Works in the editor for testing as well.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
[RequireComponent(typeof(Image))] | |
[ExecuteInEditMode] | |
public class FillBarGradientScript : MonoBehaviour | |
{ | |
public Gradient gradient; | |
Image fillImage; | |
void Start() | |
{ | |
fillImage = this.GetComponent<Image>(); | |
fillImage.fillAmount = 1; | |
} | |
void Update() | |
{ | |
if (fillImage == null) | |
fillImage = this.GetComponent<Image>(); | |
else | |
fillImage.color = gradient.Evaluate(fillImage.fillAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment