|
I stumbled upon this post which was pretty useful: http://answers.unity3d.com/questions/3209/basic-on-off-movement-using-mouse-click My dilemma isn't exactly his though. His is more toggling a button while mine is a hold. Problem 1: The button should de-activate when onMouseUp, easy modification, but it introduces another problem: Problem 2: The button should de-activate when the mouse leaves its area. So if the guy drags his mouse off the button, it should deactivate. Anybody know how to program this? Thanks in advance!
(comments are locked)
|
|
There's an OnMouseExit event which you can use just like OnMouseUp, to trigger code when the mouse is no longer over the object. You'd probably have to use this in conjunction with the mouse up/down tests to get the effect you want. (note, the comments appear to be wrong in the example on the documentation page linked above) Here's an example which activates an object when clicked, and deactivates when the mouse is released, or when the mouse exits. Notice that it also reactivates if the mouse is brought back over the object while still held down (standard behaviour for normal Mac and Windows UI buttons). I'm using a boolean variable called 'wasClicked' to remember the state, to achieve this. The Activate() and Deactivate() functions are custom functions - I have just added code which makes the object change colour as an example, but you can put whatever you want in there. Thank you so much it works!! How would I go about doing this for an iPhone seeing as how the iPhone doesn't have the mouse functions (I think)?
Jan 29 '10 at 04:03 PM
Peter B-B
But since it haven't, this is what I could use for iphone: http://forum.unity3d.com/threads/15377-quot-OnMouseDown()-quot-or-quot-OnMouseUp-quot-On-GUIT
Dec 03 '10 at 08:21 PM
Cawas
(comments are locked)
|
|
Thank you so much! Very useful.
(comments are locked)
|

thanks it works!!! =)
Asked January 29. Of last year (or, probably, earlier). :P