- Home /
Separating mouse button clicks from GUI and game input
In an imaginary game written in cSharp, I have a typical 3rd person controller and ground setup so I can walk about and punch with mouse or fire1 button. I also have a GUI menu on during gameplay to do things like cast spells - for example fireball. Now, casting fireball from the GUI and starting the punch event are separate actions, but how do I get it so when I click 'fireball' on the GUI it does not also start the punch event ?
Answer by Kleptomaniac · Mar 10, 2012 at 02:33 PM
I think that Rect.Contains(), as is described in this post by Christian H Pedersen, is your only option. Unfortunately, as he mentions, it really is a convoluted fix to what should be an easily solved problem within Unity. Until the engine itself provides better and more user-friendly control over problems like this, I think this may be the only fix.
Hopefully that helped ...
Klep
P.S - I'm a bit disconcerted as to what you mean by 'imaginary game' ... are you implying that we really are a part of the Matrix!? Mind blown (and childhood dreams realised)! ;)
Just remember to take the red pill ... :D
Haha, glad I could help! Happy travels Alice!
neo[phyte] wants to have his $$anonymous$$d blown by morpheus. morpheus wants neo to blow his ...not just his $$anonymous$$d
The imaginary game scenario was a little easier to explain than the actual game scenario - thanks for your answer, I looked up that (link/)stinky rabbit hole, what I wanted was a working example. I've searched youtube also for tutorials to no avail.. The standard solution seems to be have the menu on a separate screen , for instance a game options menu screen, but that is not what I wanted
I wouldn't take any pills, that is my matrix solution ! :)
O$$anonymous$$, try this on for size. Also uses Rect.Contains, but provides a working example. You may be able to mould it into what you want.
As I said, I believe Rect.Contains() is your only solution. Also, I found a lot of these other answers simply by Googling, so try to broaden your search before co$$anonymous$$g on UA. It isn't that I'm not happy to help you, but all I'm saying is that Neo had to get a tracking device in the form of an electronic bug sucked out of his belly button before he's able to 'find the truth', if you know what I mean. :D
Hope this helps, $$anonymous$$lep
Nope, none of them work with the latest Unity, I can't get Rect.Contains() to report that the mouse pointer is inside the Rectangle. I'll probably put GUI onto a separate screen, or assign new input (for example new fire buttons) and use those inputs to navigate the menu.
Temporary alternatives to waiting until the new GUI is released for Unity :D
Your answer
Follow this Question
Related Questions
GUI texture touch input problem 1 Answer
Updating GUI text with GetButtonDown? 1 Answer
Car AI help 0 Answers
gui list problem 2 Answers
How would I implement a GUI texture that acts as a slider? 0 Answers