Skip to content

Instantly share code, notes, and snippets.

@Volorf
Last active February 10, 2023 13:35
Show Gist options
  • Save Volorf/5be1b3fa7f7a346fbdfc3e5528685b42 to your computer and use it in GitHub Desktop.
Save Volorf/5be1b3fa7f7a346fbdfc3e5528685b42 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class ToggleColorManager : MonoBehaviour
{
[Header("Elements")]
public Toggle toggle;
public Image icon;
[Space(16)]
[Header("On State Colors")]
public ColorBlock colorBlockOn;
public Color colorIconOn;
[Space(16)]
[Header("Off State Colors")]
public ColorBlock colorBlockOff;
public Color colorIconOff;
private void Start()
{
UpdateColorSets(toggle.isOn);
}
public void UpdateColorSets(bool b)
{
if (b)
{
toggle.colors = colorBlockOn;
icon.color = colorIconOn;
}
else
{
toggle.colors = colorBlockOff;
icon.color = colorIconOff;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment