using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Slider01 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Slider>().onValueChanged.AddListener((value) => Debug.Log(value));
}
/*public void ChangeColor(string name)
{
GetComponent<Image>().color;
}*/
}
模拟进度条的填充
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Slider01 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Slider>().onValueChanged.AddListener((value) => Debug.Log(value));
StartCoroutine("ChangeValue");
}
private IEnumerator ChangeValue()
{
Slider slider = GetComponent<Slider>();
float process = 0;
while (process < 1)
{
process += 0.1f;
yield return new WaitUntil(() =>
{
slider.value = Mathf.SmoothStep(slider.value, process, 0.5f);
print("process" + process);
return process <= slider.value+0.01f;
}
);
}
}
/*public void ChangeColor(string name)
{
GetComponent<Image>().color;
}*/
}