Reputation: 846
I am trying to make my GUI creation somewhat easier and learn about it in the same time. I dont want to buy or use a third party plugin.
I am trying to make a button script that i can use overall, i have so far made it to this:
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");
}
}
When i try to OnMouseEnter i am expecting to get a print of test in the console but nothing shows up.
I guess i am missing something very fundamental and since i have found great help on stackoverflow i turn to you guys once again (you're great by the way).
Here is a screenshot:
Upvotes: 1
Views: 1187
Reputation: 497
the easiest way to do this is in OnGUI method place following code
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");
}
Upvotes: 2