【问题标题】:OnMouseEnter on Rect, Unity3DOnMouseEnter on Rect, Unity3D
【发布时间】:2013-12-04 10:19:10
【问题描述】:

我正在尝试让我的 GUI 创建更容易一些,并同时了解它。 我不想购买或使用第三方插件。

我正在尝试制作一个我可以整体使用的按钮脚本,到目前为止我已经做到了:

using UnityEngine;
using System.Collections;

[ExecuteInEditMode()]
public class SceneBTN : MonoBehaviour {

    public GUIStyle myGui;
    public int theHeight = 50;
    public int theWidth = 200;
    public float verticalPlacement = 50;
    public string buttonText = "Button Text";

    void OnGUI() {
         Rect BTNtext = new Rect(Screen.width / 2 - (theWidth / 2), Screen.height - verticalPlacement, theWidth, theHeight);
         GUI.Label(BTNtext, buttonText, myGui);
    }

    void OnMouseEnter() {
        print("test");
    }

}

当我尝试 OnMouseEnter 时,我希望在控制台中打印测试结果,但没有任何显示。

我想我错过了一些非常基本的东西,因为我在 stackoverflow 上找到了很大的帮助,所以我再次求助于你们(顺便说一句,你们很棒)。

这是一个截图:

【问题讨论】:

    标签: c# button user-interface unity3d


    【解决方案1】:

    执行此操作的最简单方法是在 OnGUI 方法中的以下代码中

    GUI.Button (new Rect(0,0,10,10), new GUIContent("Button 1", "Button 1")); 
            string hover = GUI.tooltip;
    
            if(hover=="Button 1"){
                Debug.Log("Mouse is over button 1");
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 2010-09-29
      • 2010-12-10
      • 1970-01-01
      相关资源
      最近更新 更多