- Home /
Slider issue: two sliders are used, but one takes all actions for both.
I've got a situation like this for ticking two sliders:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SliderManager : MonoBehaviour
{
public Slider sliderBarA;
public Slider sliderBarB;
Update()
{
if (Input.GetKeyDown(KeyCode.A)
{
StartCoroutine("MessWithSliderA", 0f)
}
if (Input.GetKeyDown(KeyCode.B)
{
StartCoroutine("MessWithSliderB", 0f)
}
}
IEnumerator MessWithSliderA()
{
for (float count = ABC; count > 0; count -= 1)
{
sliderBarA.minValue = 0;
sliderBarA.maxValue = 100
referenceVariableA -= 1f;
sliderBarA.value = referenceVariableA;
yield return null;
}
}
IEnumerator MessWithSliderB()
{
for (float count = XYZ; count > 0; count -= 1)
{
sliderBarB.minValue = 0;
sliderBarB.maxValue = 100
referenceVariableB += 1;
sliderBarB.value = referenceVariableB;
yield return null;
}
}
}
When I use the SliderA function, everything goes according to plan and the slider ticks down successfully. When I then use the SliderB function afterward, it ticks up sliderBarA. In effect it's doing everything it should be doing correctly, but to the wrong slider.
I've checked about a thousand times now that the correct sliders are assigned to the correct variables in the Editor since imo that's the only thing that makes sense. But nope, both sliders are referenced individually and seemingly correctly. I'm 100% lost on what might be the issue. Any ideas?
Your answer
Follow this Question
Related Questions
Simplify this code 3 Answers
Is interraction between EditorWindow and php file possible? 1 Answer
Why is this coroutine only firing once? 3 Answers
trouble looping through voicelines using Coroutine 1 Answer
Coroutine in Editor? 7 Answers