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 /
This question was closed Aug 02, 2017 at 10:32 AM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
11
Question by ArchetypeZombie · Mar 07, 2013 at 12:10 AM · whiledo

Do something while key is pressed and held down.

I am sorry for this nooby question, and I have seen similar questions on the forum, but none of the solutions are working for me. Basically what I am trying to do is while the Fire1 key is pressed, and held down I want to increase the value of testNumber by 1 continuously. Currently when I run this script I press the Fire1 button and hold it down, but the value doesnt continuously keep increasing, it will only increase again if i let go and repress the button. Any help would be really appreciated. Thanks

 var testNumber : int = 0;
 
 var testText : GUIText;
 
 function Start () {
 
 }
 
 function Update () {
 if(Input.GetButtonDown("Fire1"))
 {
 testNumber += 1;
 }
 testText.text = "" + testNumber;
 } 
Comment
Comments Locked
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

1 Reply

  • Sort: 
avatar image
33
Best Answer

Answer by robertbu · Mar 07, 2013 at 12:27 AM

Use "Input.GetButton()" instead of "Input.GetButtonDown()". Input.GetButtonDown() only returns true for the frame in which the button was pressed.

Comment
Comments Locked · Show 5 · 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 ArchetypeZombie · Mar 07, 2013 at 12:28 AM 0
Share

wow, I am so simple. Thank you so much.

avatar image gamlin777 · Mar 22, 2014 at 06:48 PM 0
Share

I also fell for this. Thank you!

avatar image Nilmag gamlin777 · Aug 02, 2017 at 09:49 AM 0
Share

I fell for this also, brother.

avatar image Atomic Nipple · Nov 23, 2014 at 07:49 PM 0
Share

Thanks, needed this.

avatar image yoeyyutch · Mar 29, 2015 at 06:49 PM 0
Share

Wow I had that backwards all along.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

While/Do loop problem(for all I know its something else) 3 Answers

Can't instantiate in loop - crashes unity 1 Answer

SOLVED! - Pick Number != These Other Numbers 2 Answers

A while type statement in the Update function, Yield? 1 Answer

How come my boost comes to an abrupt stop? 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