当前位置:   article > 正文

unity 鼠标放在button上显示名字_button鼠标放上有个name

button鼠标放上有个name

新建一个脚本 继承button 里面可以获取button 的四中状态 在里面可以写一些要触发的事件
using UnityEngine;
using UnityEngine.UI;

public class Button_Faker : Button
{
enum Selection
{
Normal,
Highlighted,
Pressed,
Disabled
}
Selection selection;

protected override void DoStateTransition(SelectionState state, bool instant)
{

    base.DoStateTransition(state, instant);
    switch (state)
    {
        //四种状态
        case SelectionState.Normal:
            selection = Selection.Normal;
            break;
        case SelectionState.Highlighted:
            selection = Selection.Highlighted;
            break;
        case SelectionState.Pressed:
            selection = Selection.Pressed;
            break;
        case SelectionState.Disabled:
            selection = Selection.Disabled;
            break;
        default:
            break;
    }
}

private void OnGUI()
{
    GUI.skin.box.fontSize = 12;
    switch (selection)
    {
        case Selection.Highlighted:
            GUI.Box(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 100, 25),this.name);
            break;
        case Selection.Pressed:
           // GUI.Box(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 100, 25), "Pressed");
            break;
        default:
            break;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

}

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/542866
推荐阅读
相关标签
  

闽ICP备14008679号