- Home /
Prevent 'Hold' Of A Mouse Click
Hello,
I have a veryy simple script that basically says when Fire1 is pressed, play Fire animation (recoil of a pistol) - and it works very well. The thing is, if I were to hold down the mouse button, my pistol turns into a fully automatic death machine.
Is there a way to prevent the 'hold status' of a mouse button - so the user has to keep clicking in order to fire instead of just holding it down - maybe within 2 seconds of each other?
I'm sure this is a easy solution and apologies if it has been repeated.
Ollie
im trying to make an automatic weapon how did you make it so when you hold the mouse button it continuously fires ?
Answer by AliAzin · Jan 23, 2011 at 12:06 PM
Hi, You can simply use Input.GetButtonDown(). Then you can set a boolean to prevent player from shooting in next two seconds.
How the hell did I not think of that -- its been a longgg day
And I was breaking my head trying to do that... almost gone mad when found this is so simple!
You can also use if(!animation.isPlaying) to ensure it will only play after the fire animation is complete.
Answer by FLASHDENMARK · Jan 23, 2011 at 12:08 PM
I assume that it is a easy fix.
Input.GetButtonDown("Fire1")
Only works once, and then you have to release the button and click it again in order for it excute.
Your answer
Follow this Question
Related Questions
Input: Mixing axis and buttons (ie: Input.GetAxis versus Input.GetButton) 4 Answers
Press button once to enter vehicle and once again to exit 1 Answer
How can I check if a key/button is not (!) being held down? 1 Answer
Weird Input System situation 1 Answer
How can I use multiple GetButtonDown keys simultaneously? 2 Answers