- Home /
Trigger a Button Click
Hi, I want to make a script so that when I click one button, another button is clicked. I don't just want the script of the other button to run, I want to see the color of the second button change when I click the first button. I code in C#. Does anybody know how to do this? I've already looked online for things like this, and I found scripts that trigger buttons, but none where you can actually see the color of the button change.
Thanks!
The button click event is literally just that, a button click event. To simulate it, you would alter the sprite image of the button, giving a color change effect, then setting it back to its original color. This is all the button visuals do in the first place.
Answer by UnityCoach · Feb 22, 2017 at 09:24 PM
You can use the submitHandler
BaseEventData data = new BaseEventData (EventSystem.current);
ExecuteEvents.Execute (secondButton.gameObject, data, ExecuteEvents.submitHandler);
Answer by Cycy · Feb 22, 2017 at 03:52 PM
Hello ! did you try this ?
secondButton.getComponent<Button>().Select(); // it will highlight the button
Otherwise you can modify the color of the second button like this :
secondButton.image.color = newColor;
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How do I trigger an animation using a button? 3 Answers
UI button doesn't appear - c# 3 Answers
Builded game dont work with self made bluetooth mouse controller. 0 Answers
Trigger Sound more than Once 0 Answers