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 btunick26 · Nov 23, 2021 at 10:27 PM · mouse button

Force GetMouseButtonUp

I've got an action in my game that has you clicking and holding and then something fires off on releasing, but I want to have it on a timer so that it automatically releases after X amount of time.


The problem is even doing things like making a bool part of the mousebuttondown if statement and then disabling it after a certain time doesn't stop the current mousebuttondown. I need a way to force end the current action, basically forcing mousebuttonup without the input of the player. Any ideas?

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 didicayu · Nov 24, 2021 at 05:39 PM 0
Share

Hello, could you let me know if my solution worked for you? I'd like to know whether this was helpful for you or not

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by didicayu · Nov 23, 2021 at 11:27 PM

You actually also have the function GetMouseButton( ) that detects when the mouse is being held and not just when it is pressed or released, you could make a timer so that the action only fires off after a certain amount of time, here's an example:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MouseButton : MonoBehaviour
 {
     public float delay = 10f;
     float timepassed = 0;
 
     // Update is called once per frame
     void Update()
     {
         if(Input.GetMouseButton(0) && timepassed > delay){          
             Debug.Log("fire");
             timepassed = 0;
         }
         timepassed += Time.deltaTime;
     }
 }

where the delay is the time in the number of seconds you want to wait for before doing the action again. Regardless of whether the user is having the mouse pressed all the time or not, the action will not be fired until the indicated time has passed

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 btunick26 · Nov 25, 2021 at 01:38 AM 0
Share

Hm, this puts a delay on the initial press of the button, but I need an action to happen after a certain time that disrupts the current GetMouseButton situation, basically the action for clicking and holding the mouse holds a ball in place and then releasing it launches the ball, so if I force launch the ball but the player is still holding the button it may "launch" but immediately it goes back to being static because the mouse button is still being held.

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

130 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 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

Is it possible to do 'click to move' in the free version of Unity 1 Answer

Right click not working in the editor with sub windows. 0 Answers

"Click" a GUI Button using only joystick input 1 Answer

Input.GetMouseButtonDown(1): do the primary and secondary buttons work differently? 1 Answer

setting up mouse button 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