using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class OneKeyOperation : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void AllOpen() { foreach(Transform child in transform.Find("Sliders").transform) { StartCoroutine(SmoothIncreaseToTwo(0.3f, child)); } } public void AllClose() { foreach (Transform child in transform.Find("Sliders").transform) { StartCoroutine(SmoothDecreaseToZero(0.3f, child)); } } IEnumerator SmoothDecreaseToZero(float duration,Transform child ) { float startValue = child.GetComponent().value; float time = 0f; while (time < duration) { time += Time.deltaTime; startValue = Mathf.Lerp(startValue, 0f, time / duration); child.GetComponent().value = startValue; yield return null; } child.GetComponent().value = 0f; } IEnumerator SmoothIncreaseToTwo(float duration, Transform child) { float startValue = child.GetComponent().value; float time = 0f; while (time < duration) { time += Time.deltaTime; startValue = Mathf.Lerp(startValue, 2f, time / duration); child.GetComponent().value = startValue; yield return null; } child.GetComponent().value = 2f; } }