Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by jakebacker · Sep 02, 2016 at 06:45 PM · mousemouseclicktiming

Detect mouse press and release

I want to detect if the user pressed the mouse button and released it within one second.
Example: The user holds down the left mouse button for more than a second. => function returns false.
The user holds down the left mouse button and releases in less than a second. => function returns true;

Comment
Add comment · Show 1
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 doublemax · Sep 02, 2016 at 11:38 PM 1
Share

On mouse button down store the current time (Time.time) in a float variable.
On mouse button up compare the current time with the stored value.
If the difference is less than 1 you have what you're looking for.

3 Replies

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

Answer by LuckierBread · Sep 02, 2016 at 08:12 PM

Hi,

I'm no pro but I would go about this by using Input.GetMouseButtonDown. it works by making a bool true as long as the mouse button is pressed down. I would then attach a timer to that so that when the button is pressed it starts a clock then when the bool turns false stop the timer and then use an if else function to decide to make an output true or false.

you can check this out if you have any other questions about Input.GetMouseButtonDown https://docs.unity3d.com/ScriptReference/Input.GetButtonDown.html

Remember to pick this as the best answer and upvote if this helped. =)

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 jakebacker · Sep 02, 2016 at 09:32 PM 0
Share

This is what I though but I can't figure out how to use a timer.

avatar image LuckierBread jakebacker · Sep 03, 2016 at 01:31 AM 0
Share

Here bud wrote a script just for you

 private float clickStart;
 private bool moreThenOne;

 void Update ()
 {
     if (Input.Get$$anonymous$$ouseButtonDown(0))
     {
         clickStart = Time.time;
     }

     if (Input.Get$$anonymous$$ouseButtonUp(0) && Time.time - clickStart >= 1)
     {
         moreThenOne = true;
     }
     if (Input.Get$$anonymous$$ouseButtonUp(0) && Time.time - clickStart < 1)
     {
         moreThenOne = false;
     }
 }
avatar image
0

Answer by TheGreenCode · Mar 20, 2020 at 07:18 PM

Question: How do you check if RIGHT MOUSE DOWN?

Comment
Add comment · Show 1 · 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 zhaorongtuzt7 · Jun 06, 2020 at 08:44 PM 0
Share

Input.Get$$anonymous$$ouseButtonDown(0)

avatar image
0

Answer by SuhaimKhalid · Jul 20, 2020 at 09:35 PM

Just change if (Input.GetMouseButtonUp(1)) { do whatever }

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

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

75 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Limited response from mouse input in game view. 2019.3 0 Answers

Detect mouse inputs when the scene is changing to another scene. 2 Answers

CATCH MOUSE CLICK EVENT ON OBJECTS 0 Answers

Mouse Clicks Stop After X# of clicks 0 Answers

Event on mouse up 2 Answers


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