Question by
Willy_Wonder · Apr 27, 2017 at 01:02 PM ·
guimousepositiononmousedowngui.buttonguibutton
GUI Button Moving with a mouse
Heya! I've got another question. here is my code (written with a lot of help here in forum!) :
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class ClickOnAlarm : MonoBehaviour { private bool showText = false;
void OnMouseDown()
{
if (!showText)
showText = true;
}
void OnGUI()
{
if (showText)
{
var x = Event.current.mousePosition.x;
var y = Event.current.mousePosition.y;
if(GUI.Button (new Rect (x -150, y +50, 300, 60), "Anlage braucht dringend Wartung")) // Position und Größe des Buttons
showText = false;
}
}
}
now what my problem is, is that the GUI Button moves with my mouse. what i want is that my button appears when i click on an object (herefor mouseposition), and STAYS there, when i move my mouse away, before i close the button with another mouseclick.
pleeeease help me! :>
Comment