I’m currently rewriting a character creation menu that I made a few weeks ago and I came across this weird with my color selector. I try using Unity events to notify the color selector observers that the color has changed, but even though only one button is supposed to be affected, the entire UI changes color and I don’t see any changes in the inspector’s materials.
Color Selector (Shortened)
//EVENT
public UnityEvent e_OnColorChanged;
//RGB Sliders
public Slider sliderR;
public Slider sliderG;
public Slider sliderB;
void Start(){
sliderR.onValueChanged.AddListener(updateColor);
sliderG.onValueChanged.AddListener(updateColor);
sliderB.onValueChanged.AddListener(updateColor);
}
private void updateColor(float arg) {
color = new Color(sliderR == null ? 255 : sliderR.normalizedValue,
sliderG == null ? 255 : sliderG.normalizedValue,
sliderB == null ? 255 : sliderB.normalizedValue);
if (OnColorChanged != null) {
OnColorChanged();
}
}
Character Creation Menu (Shortened)
void Start(){
GameObject.Find("Button_Skin_Color").GetComponent<Button>().onClick.AddListener(onclicktest);
}
private void onclicktest() {
colorSelector.OnColorChanged.AddListener(ApplyColorToObject);
}
private void ApplyColorToObject(Color newColor) {
GameObject.Find("Button_Skin_Color").GetComponent<Image>().material.color = newColor;
}
I tried with both delegate function and the above UnityEvent system, both giving me the same result. Anyone knows what I’m doing wrong? :l