Question by
twigmytwig · Aug 03, 2020 at 11:25 AM ·
script.bugdebugslider
Why is my slider going to 100% in this coroutine as soon as it is run?,Why is my slider going to 100% as soon as the method runs?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class GlobalIndenturedServitude : MonoBehaviour { public static bool startServitude = false; public GameObject sliderObjects; public Slider slider; public GameObject sliderText; public int unrestValue = 0; public int unrestIncreaseValue = 10; public int timedUnrestIncrease = 2; //how long it takes to increase the amount of unrest // Start is called before the first frame update void Start() { slider.maxValue = 100; slider.value = 0; sliderObjects.SetActive(true); }
// Update is called once per frame
void Update()
{
if (startServitude)
{
//slider.value = unrestValue;
//sliderObjects.SetActive(true);
StartCoroutine(StartServitude());
//unrestValue += 10;
}
sliderText.GetComponent<Text>().text = "Unrest level: " + slider.value + "%";
}
public static void init()
{
startServitude = true;
}
IEnumerator StartServitude()
{
slider.value += 10;
yield return new WaitForSeconds(2);
//unrestValue += 10;
//unrestValue = unrestIncreaseValue;
//unrestIncreaseValue += 10;
//yield return new WaitForSeconds(5);
}
}
Comment
Answer by xPrizrakSHIZAx · Jul 07, 2021 at 04:14 PM
Check slider min max values. By default slider have maximum 1f and min 0f