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 Crimson Valor · Nov 27, 2012 at 03:40 PM · mouseupdateclickleftheld

Only updating once during left mouse button being held down.

I'm trying to detect when left click is held down on every frame, it should check to see if it still being held. I've put it in 'function Update' but it only shows up once even when held down. I want it to continuously detect it until released.

Code:

 function Update () {
     if (Input.GetMouseButton(0))
     {
         IncreasePowerBar();
     }
 }
 
 function IncreasePowerBar()
 {
     Debug.Log("fire button");
 }

Currently the Log only shows once when the LMB is held down, and doesnt even show a second time even if I release and re-click

Thanks in advance

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AlucardJay · Nov 27, 2012 at 03:55 PM

Do you have your console collapsed?

In the Console window, make sure the tab Collapse is off !

http://docs.unity3d.com/Documentation/Manual/Console.html

When Collapse is enabled, identical messages will only be shown once.

It catches a few people !

http://forum.unity3d.com/threads/88068-collapse-in-console-just-spent-an-hour-debugging-code-that-did-not-have-a-problem

Comment
Add comment · Show 2 · 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 Crimson Valor · Nov 27, 2012 at 03:59 PM 0
Share

I feel so stupid right now, thanks for this

avatar image AlucardJay · Nov 27, 2012 at 04:00 PM 0
Share

No worries, just added more info, but glad it fixed the problem =]

avatar image
1

Answer by CarlLydon · Apr 06, 2014 at 06:33 AM

In the manual it says:

Description Returns true during the frame the user pressed the given mouse button.

That means it will only trigger once, when you click. To do continuous stuff based on the mouse being up or down, you will need to toggle a variable when you click down, and toggle it again when you click up.

Comment
Add comment · 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
0

Answer by Landern · Nov 27, 2012 at 03:42 PM

Input.GetMouseButtonDown documentation.

 function Update () {
     if (Input.GetMouseButtonDown(0))
     {
        IncreasePowerBar();
     }
 }
 
 function IncreasePowerBar()
 {
     Debug.Log("fire button");
 }

Comment
Add comment · Show 3 · 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 Crimson Valor · Nov 27, 2012 at 03:48 PM 0
Share

Still no change. only updates once

avatar image Landern · Nov 27, 2012 at 03:51 PM 0
Share

Add a Debug.Log("$$anonymous$$ouse Button 0 Down") into the updates if block, if by clicking and holding and repeating, do you get the log message?

avatar image Crimson Valor · Nov 27, 2012 at 03:56 PM 0
Share

The Debug.Log does detect the mouse button being clicked, but i only comes up once. When i click multiple times it does nothing.

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

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Converting button to mouse click 1 Answer

Unity doesn't recognize mouse clicks, C# 1 Answer

Click Sound 1 Answer

Mouse-click movement 0 Answers

Change Camera on (Right) Mouse Click 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