Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ShedHead · Jan 24, 2017 at 05:31 AM · raycastinputmouseonmousedownonmouseup

How do I use Input.GetButton, instead of OnMouse()

I realize this question may be "silly" but I'm new to C#. I'm using this script example i found for a keypad:

void Update () { Debug.Log (playerCode);

     if (totalDigits == 4)
     {
         if(playerCode==correctCode)
         
         {
             playerCode = null;
             theDoor.GetComponent<Animation> ().Play ();
             theDoor.GetComponent<AudioSource> ().Play ();
             
             Debug.Log ("Correct");
         }
     

         else
         {
             playerCode="";
             totalDigits = 0;
             Debug.Log ("Wrong");
         }
     }
 }
     
 void OnMouseUp()
 {
     GameObject.FindWithTag ("KeypadButton");
     playerCode += gameObject.name;    
     totalDigits += 1;
     keySound.GetComponent<PlaysoundScript> ().Clicky ();
 }

This script works fine in the editor when using the mouse, But I want the "OnMouseUp Click" to be done with a gamepad button in the Input manager

I tried moving the OnMouseUp() function inside Update, adding Raycast etc. What am I missing? Any help would be appreciated, Thanks.

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

Answer by JJMGsoftworks · Jan 24, 2017 at 04:07 PM

I don't know how to do exactly what you need but i have an alternative. I always use the key up bool to check if a key is up.

 Input.GetButtonUp()

simply fill in the key/button you are checking and if it is true just call a OnMouseup . You may need to make a new method name if doing this

  if(Input.GetButtonUp(yourbutton))

      OnMouseUp();

I hope this answer is what your looking for. It should at least get you going if your still stuck

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 ShedHead · Jan 24, 2017 at 06:19 PM 0
Share

This answer was very helpful, Thank you!

I called "On$$anonymous$$ouseUp()" from inside "Update()".

Ex. void Update() { If(GetButtonDown("Ok")) { On$$anonymous$$ouseUp(); }

When i click the keypad keys with the mouse... it still works! (prints individual key names ex. 1, 5, Cancel, 8, etc)

But, when i use the "Ok Button", for some reason, the console prints out a whole bunch of random number combinations... Ex. 157,9,Cancel659,8693,

Any idea why?

Thanks!

avatar image JJMGsoftworks ShedHead · Jan 24, 2017 at 07:08 PM 0
Share

This is just a strong guess but try making a method exactly like on mouse up but name it something different. Then in on mouse up you could call that method and also call it if GetButtonDown(ok). This way it will be exactly as it is now but without the error.

I am guessing this will work based on experience with $$anonymous$$onogame so it may not help in unity. I am assu$$anonymous$$g that the On$$anonymous$$ouseUp cannot be evoked in code. Please get back to me if it works I can also explain further.

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

119 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

Related Questions

how to stop mouse from teleporting or detect better, so that i can detect if a swipe of mouse was over object 0 Answers

Can't call raycast on plane to get mouse position? Beginner Question 1 Answer

OnMouseDown/Drag/ets is not being called in WebGL build 0 Answers

How to check if a player click on a object: Android Mobile 1 Answer

What I do wrong ? (OnMouseDown) 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