Hello, I have a question regarding the UI Button. When you hover your mouse over the button, it fades to a color, is it possible to get the current color of the button? Thanks!
If you mean the colors for the button itself https://docs.unity3d.com/ScriptReference/UI.ColorBlock.html which is under the colors property https://docs.unity3d.com/ScriptReference/UI.Selectable-colors.html
No, I need to know the current color of the button in real-time, while playing. This would make it a lot easier to know if the mouse is hovering the button or not
Then just use the second link. Check what button.colors returns to see what state it's in. It returns a colorblock enum. But honestly, I believe there are triggers that will tell you what you want to know, so would be easier probably using those. https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html Or the ipointer. Can detect when enters and when exits https://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.html
I know it's an old topic and the last post has probably pointed the right way to solve what it was asked in first place, but I couldn't find a thing about how to get the Button color in realtime until I figured it out by looking at the UI source code. In order to get the color changed by the Button, one just need to check the CanvasRenderer attached to the Graphic component used by the Button, which usually is the Image in the same GameObject. Here goes an example: Code (CSharp): public class ColorClone : MonoBehaviour { private Graphic target; public Graphic Source; private void Awake() { this.target = this.GetComponent<Graphic>(); } private void LateUpdate() { this.target.color = this.Source.color * this.Source.canvasRenderer.GetColor(); } } Add this script to any GameObject that has a Graphic (like an Image) and drag the Graphic used by the Button (the Button GameObject has an Image) to see its color changing as the button state changes. Maybe there's a better way to do that, but anyway I hope it can help someone.