Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Graham · Sep 30, 2010 at 08:42 PM · inputbuttonmouse

Keypress interferes with mouse hover

Hello,

I have a script that requires the player to hover the mouse over an object and hold a key down (z). I set it up so the GUI displays some information OnMouseEnter, and clears that information OnMouseExit. However, it seems that holding down z rapidly activates and deactivates the mouse cursor, so that it switches between Enter and Exit, causing the GUI to flicker. Does anyone know how to make held down keys leave the mouse alone?

Thanks for taking a look at this.

EDIT: Here's an update with some script: Here's what's on the object to display and clear the GUI data:

function OnMouseExit () {

guidata.tipname = null;

guidata.tiphits = 0;

guidata.tiphead = null;

guidata.tiptorso = null;

guidata.tiplegs = null;

}

 <p>function OnMouseOver () {</p>

var unitdata = gameObject.GetComponent(state);

guidata.tipname = unitdata.unitid;

guidata.tiphits = unitdata.hits;

guidata.tiphead = unitdata.head;

guidata.tiptorso = unitdata.torso;

guidata.tiplegs = unitdata.legs;

}

Hmm, the thing killed my formatting, but I think you can tell what's going on.

And here's the keypress:

function Update () {

if (Input.GetButton("z")){

gameObject.renderer.enabled = true;

}

if (!Input.GetButton("z")) {

gameObject.renderer.enabled = false;

}

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image skovacs1 · Sep 30, 2010 at 08:57 PM 0
Share

Could you include some of your script?

avatar image · Oct 01, 2010 at 02:50 AM 0
Share

The formatting was killed because you used the 'blockquote' button rather than the 'code' button (next to it - 1's and 0's).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by · Oct 01, 2010 at 02:50 AM

I haven't tested with your code, so I can't see the described problem, but there are a few things I noticed:

  • You should probably do the GetComponent once, in Start(), rather than every time you release the mouse.

  • You should probably rewrite your Update keypress script to use GetButtonUp/GetButtonDown.

For example:

function Update ()
{
   if ( Input.GetButtonDown("z"))
   {
      gameObject.renderer.enabled = true;
   }
   else if ( Input.GetButtonUp("z"))
   {
      gameObject.renderer.enabled = false;
   }
}

Edited to remove OnMouseUp/OnMouseExit references (wrong code was pasted into question).

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham · Oct 01, 2010 at 03:17 AM 0
Share

Whoops! I did paste the wrong code. How embarrassing. Fixed. I don't believe it's a coding problem, however, I think it's the way Unity processes inputs. And I don't know how flexible that is... Thanks!

avatar image · Oct 01, 2010 at 03:59 AM 0
Share

No worries. I'm not sure of a possible cause - just posting a few suggestions that might help your code overall, even if it doesn't fix the described problem!

avatar image Graham · Oct 01, 2010 at 05:18 AM 0
Share

I appreciate it. I did move those dang variables up and have them grab the component once. I'll keep fiddling with this.

avatar image · Oct 01, 2010 at 05:30 AM 0
Share

I'm home in a few hours, and will try to remember to use your code to reproduce the issue (if no-one else has solved it by then).

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to detect number of mouse/trackpad buttons? 0 Answers

Simulate a mouse Click? 2 Answers

Can't interact with UI when using a virtual mouse, 0 Answers

OnMouse menu 1 Answer

Check if mouse is down while in Edit Mode 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges