Skip to content

Commit

Permalink
Change difficulty text on sluder value change
Browse files Browse the repository at this point in the history
  • Loading branch information
thewithz committed Jan 30, 2020
1 parent c184c66 commit 730f856
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion OdysseyNow/Assets/Scripts/Graphics/ToggleButtonBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
namespace Graphics
{
/// <summary>
/// Behavior of all menu buttons in the main menu (and pause menus).
/// Behavior of AI toggle buttons and their sliders
/// </summary>
public class ToggleButtonBehavior : MonoBehaviour
{
// slider to choose AI difficulty
public Slider difficultySlider;
public Text sliderText;

/// <summary>
/// On start, set button click listener.
/// </summary>
void Start()
{
gameObject.GetComponent<Toggle>().onValueChanged.AddListener(ToggleClicked);
difficultySlider.onValueChanged.AddListener(value => SliderChanged());
// hide the sliders parent by default
difficultySlider.transform.parent.gameObject.SetActive(false);
}
Expand All @@ -35,5 +37,13 @@ void ToggleClicked(bool on)
difficultySlider.transform.parent.gameObject.SetActive(false);
}
}

/// <summary>
/// On slider value change, update text to reflect difficulty
/// </summary>
void SliderChanged()
{
sliderText.text = "Difficulty: " + difficultySlider.value;
}
}
}

0 comments on commit 730f856

Please sign in to comment.