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
1
Question by Zlong101 · Feb 02, 2020 at 06:03 PM · mouse input

Why does if (Input.GetMouseButton) doesn't work on my unity?

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class FirstScript : MonoBehaviour {

 // Start is called before the first frame update
 void Start() {

 

}

 // Update is called once per frame
 void Update() {

     if (Input.GetMouseButton(0))
     {

         print("left mouse button click.");

     }

     if (Input.GetMouseButton(1))
     {

         print("right mouse button click.");

     }

     if (Input.GetMouseButton(2))
     {

         print("middle mouse button click.");
     }
     

 }


}

Why is this script not detecting my mouse in the unity console. The unity version that I'm using is 2019.13f1 and my mouse is a Logitech (G502). I did change my mouse and test it on my laptop track pad but it doesn't seem to work.

Please help me and give an explanation on how to fixed this issue

Comment
Add comment · Show 7
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 logicandchaos · Feb 02, 2020 at 06:14 PM 0
Share

Looks fine, what object did you put your script on?

avatar image sacredgeometry · Feb 02, 2020 at 06:14 PM 0
Share

Have you put the script on a gameobject in your scene?

avatar image Zlong101 sacredgeometry · Feb 03, 2020 at 03:34 AM 0
Share

Yes I did put it on a gameobject and the console doesn't me anything. I also tried if(Input.GetButtonDown ("Fire1")) { print("Left mouse button pressed"); and it doesn't work too. But my keyboard works though when I use ("Jump").

avatar image kskjadav007 Zlong101 · Feb 03, 2020 at 12:34 PM 0
Share

alt text

Put Debug in Update Check if that's working.

annotation-2020-02-03-180323.png (21.4 kB)
Show more comments
avatar image JPhilipp · Feb 03, 2020 at 01:36 PM 0
Share

Your script works fine here. Did you by any chance accidentally untick the "show debug messages" icon at the top right of the bottom console? The gray for active and the gray for inactive are not very differentiated in the newer Unity UI designs.

avatar image Zlong101 JPhilipp · Feb 03, 2020 at 04:01 PM 0
Share

I did check but still doesn't work

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by joker_yash96 · Feb 03, 2020 at 01:54 PM

GetMouseButton is for when BUTTON is on HOLD, not CLICK


Use Input.GetMouseButtonDown


Check this for more Reference.

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 Zlong101 · Feb 03, 2020 at 03:52 PM 0
Share

still doesn't work though

avatar image joker_yash96 Zlong101 · Feb 04, 2020 at 05:07 AM 0
Share

Can I get more Information about the code?

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

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

Related Questions

Problem with Clamping Mous Y input 0 Answers

How to draw a path so that game object is following it? 0 Answers

Different values for Axis parameters "Mouse Y" (Z) 0 Answers

Problem with mouse movement type input during the building project 0 Answers

Unity 2D jump in mouse direction 2 Answers


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