using UnityEngine; using System.Collections; using UnityEngine.UI; public class RatioProgression : MonoBehaviour { private Material _material; void Awake() { if (GetComponent() != null) { // GetComponent().material creates its own instance of the material, so it's not shared _material = GetComponent().material; } else if (GetComponent() != null) { // For the UI images, GetComponent().material is a shared material, so we have to clone it _material = Instantiate(GetComponent().material); GetComponent().material = _material; } } public void SetCompletedRatio(float ratio) { _material.SetFloat("_Ratio", ratio); } }