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
Looks fine, what object did you put your script on?
Have you put the script on a gameobject in your scene?
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").
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.
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.