- Home /
Question on Update()
Hi,all! I'm trying to make a window that could only be shown when the user both hover the mouse on the object and press the "return" button, but it seems there's something not right. Here is my code:
function OnMouseEnter () { MouseSwitch = true; print("Entered"); }
function OnMouseExit () { MouseSwitch = false; }
function Update () { if(MouseSwitch && (Input.GetKeyDown(KeyCode.Return))) { gameObject.GetComponent(menu).enabled = true; SwitchEnabled = true; } }
Can anybody give me a hand? THX!
I change the judge statement a little bit like shown below, this time the code works normally even though I dont know whats the different between this and the one before. And thanks, folks! here is the code:
function Update () {
if( MouseSwitch == true && Input.GetKey("return") ) {
print("Correct!");
SwitchEnabled = true;
gameObject.GetComponent(menu).enabled = true;
}
}
Answer by AliAzin · Aug 26, 2010 at 06:26 PM
OnMouseEnter() only works with colliders and GUI elements. you should add a collider component to your object.
$$anonymous$$y object is a cube and has a collider already. "Entered" will be printed in the debug info when i hover my mouse on the object. The question is " if($$anonymous$$ouseSwitch && (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return)))",when my mouse cursor is on the object and i press the return button, the code under this "if" wont be executed. I dont know why...
theres nothing wrong with every single jugdement, but when im trying to add an "&&" between them, it seems that it cant judge correctly.