[英]OnMouseEnter on Rect, Unity3D
我試圖使我的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上找到了很大的幫助,所以我再次求助於您(順便說一句,您很棒)。
這是屏幕截圖:
最簡單的方法是在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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.