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 john-essy · Apr 12, 2012 at 01:07 PM · input

Input.GetMouseButton

Hi there i have a major problem. I have created a melee system using ray-casting and i need it to cast the ray while animation is being played this works great. My problem is the Input.GetMouseButton method reading on the refrence after a long think i found that you must press the button then release then press again i need it to be just a press none of this press again jargon.

Within my melee system when the user presses the LMB i run a another method which is the melee systems main port of call for detecting hits and what it hit.

Is there anything other than this or am i doing something wrong i am 100% sure i am not i hope there is some sort of solution that someone can help with. here is some code that is within the update method

 if(Input.GetMouseButtonUp(0))
         {
             attacking = true;
             animations.animation.Play("Down");
             CheckAnims();
         }
     }
     
     void CheckAnims()
     {
         if(animations.animation.IsPlaying("Down"))
             {
                 if (Physics.CapsuleCast(point1, point2, radiusOfCapsule, direction, out hit, length))
                 {
                     if(hit.collider.gameObject.tag == "Enemy")
                     {
                         if(attacking)
                         {
                             StartCoroutine(MeleeSystem());
                         }
                     }
                 }
               }
     }
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 yezzer · Apr 12, 2012 at 01:12 PM 0
Share

Can you post some code so we can see what you're doing?

2 Replies

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

Answer by john-essy · Apr 12, 2012 at 09:55 PM

I realised i needed a coroutine in the update function whether or not the attacking boolean was true if it was run the code. The reason it was not working was i was running code within the Mouse Event which only returns true for one frame.

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

Answer by fafase · Apr 12, 2012 at 01:32 PM

GetMouseButtonUp/down means it sends 1 on the frame when you release/press the button.But the rest of the time it sends 0

GetMouseButton sends 1 on every frame you are pressing the button so as long as yuo keep pressing.

Your question is not so clear to me but maybe that is what you need.

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 john-essy · Apr 12, 2012 at 02:12 PM 0
Share

I have noticed that when i press the L$$anonymous$$B it will play the animation and any debugs i do as expected. What i have also realised is that when i press the button some times it does not run the checkAnims method but if i press the button twice in quick succession it will run the method. This is the problem i need it to run the method everytime the button is pressed.

avatar image rutter · Apr 12, 2012 at 10:18 PM 0
Share

As fafase says, you should use Get$$anonymous$$ouseButton() if you want to get true on every frame the button is held down. The function you're using in the posted sample will only return true on the precise frame where the user released the button.

Also important: using ButtonUp/Down from FixedUpdate() can cause unexpected results. $$anonymous$$ake sure that you're calling this from Update() specifically.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Order of 2D Colliders 1 Answer

How do I separate OnMouseDown() from OnMouseDrag() 0 Answers

Input.GetButtonUp activates twice? 0 Answers

Separating Input.GetKey and Input.GetKeyDown 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