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 todd85 · Oct 13, 2014 at 02:09 AM · inputupdate

Variable continuously add up in Update()

Hi All, I'm a newbie.

I'm having a really odd problem here, the filed I defined just continuously add up in Update() function.

This is my code:

 using UnityEngine;
 using System.Collections;
 
 public class MenuManager : MonoBehaviour {
 
     private int counter = 0;
 
     void Update ()
     {
         ShowSelectedMenuItem ();
     }
 
     private void  ShowSelectedMenuItem() {
 
         if (Input.GetAxisRaw ("Vertical") > 0.9) {
             
             
         } else if (Input.GetAxisRaw ("Vertical") < - 0.9) {
 
             Debug.Log("s Down");
             
             counter=counter+1;
             
             Debug.Log (string.Format("counter {0} ",counter));
             Debug.Log("Finish s down");
         
         }
         }    
 }

I'm excepting output like these: s Down counter 1 Finish s down

However, In log I got: s Down counter 1 Finish s down counter 2 counter 3 counter 4 counter 5 counter 6 counter 7 counter 8

This is really odd, No matter what I do, I have tried counter++, counter = (counter+1). Makes no different. After the function, counter just keep add up another 7 times but "s Down" and "Finish s down" never showed second time. This script attached to an empty object in a empty project. My editor version is 4.5.4

Any help would be appreciated

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

1 Reply

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

Answer by Bunny83 · Oct 13, 2014 at 02:16 AM

You have pressed the "collapse" button at the top of your console window. If that button is toggled on the console will collapse / group the same message into one. That's why you don't see the other logs, bug they are there.

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 todd85 · Oct 13, 2014 at 02:30 AM 0
Share

Thanks a lot! How can I make the function occur only once for each key press?

avatar image Bunny83 · Oct 13, 2014 at 02:43 AM 0
Share

Uhm, i'm not sure what you mean. You're using GetAxisRaw which returns the state of the virtual axis. If you want to check for a single keypress, you have to use either Input.GetButtonDown if you want to use virtual buttons (defined in the input manager), or Input.Get$$anonymous$$eyDown with a $$anonymous$$eyCode of a specific key.

 if (Input.GetButtonDown("NameOfAButtonInTheInput$$anonymous$$anager"))
 
 
 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W))

I guess that's all you want. If not, be more specific ;)

avatar image todd85 · Oct 13, 2014 at 09:00 AM 0
Share

Input.Get$$anonymous$$eyDown worked, thanks a lot.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why am I losing some inputs on Update function? 0 Answers

How to Count an Input, key press on keyboard 1 Answer

Eliminating input loss 1 Answer

How can I get user-defined inputs? 1 Answer

Input.GetKey not working 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