🟥 Unity获取点击到的UI物体
将下面方法写在Button的点击事件里,即可传出当前button所依赖物体的名称
var obj = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject; Debug.Log(obj .transform.name);
🟧 修改Button颜色
ColorBlock cb = new ColorBlock(); cb.normalColor = Color.white; cb.highlightedColor = Color.white; cb.pressedColor = Color.white; cb.disabledColor = new Color(1, 134 / 255f, 0, 1); cb.colorMultiplier = 1; obj.transform.Find("Button").GetComponent<Button>().colors = cb;
🟨 Button为Sprite模式下,修改不同状态图片
button.transition = Selectable.Transition.SpriteSwap; //设置变化状态 SpriteState state = new SpriteState(); state.highlightedSprite = highlightedSprite; state.pressedSprite = pressedSprite; state.disabledSprite = disabledSprite; button.spriteState = state;