So i’m trying to make a script that makes a Gui label appear when I have the mouse over an object and press E to “interact” with it. So far i’ve got the gui label to appear with just mouse over, but I only want it to appear with mouse over AND when I press E. I’ve tried placing if (Input.GetKeyDown (KeyCode.E)) but to no avail. What would be the next step into making this script work? Thanks.
var mouseOver : boolean = false;
function OnMouseEnter() { mouseOver = true; }
function OnMouseExit() { mouseOver = false; }
function OnGUI() {
if (mouseOver) {
GUI.Label (Rect (10, 10, 100, 20), "Hello World!");
}
}
It doesn’t seem to do anything at all now (except the “mouse over” check box gets ticked whenever I do mouse over the object, so that is working, but I had that working anyway) . This is my script currently adding what you just gave me (I think I did it right, i’m still relativly new to this.) Is the following correct?
var mouseOver : boolean = false;
function OnMouseEnter() { mouseOver = true; }
function OnMouseExit() { mouseOver = false; }
function OnGUI() {
if(mouseOver Input.GetKeyDown (KeyCode.E))
{
GUI.Label (Rect (10, 10, 100, 20), "Hello World!");
}
}
Sry, i didn’t thought too much before posting. The reason why the above code is not working is the fact that Input.GetKeyDown() is a one time event and is triggered only once, while the code in OnGUI() is executed each frame. This should work: