Last active
February 10, 2023 13:35
-
-
Save Volorf/5be1b3fa7f7a346fbdfc3e5528685b42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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