I am creating a custom sound for whenever a key is pressed, to simulate an old typing sound effect in C#.
However, I can’t find a way to completely ignore mouse clicks, so that only pressing keyboard keys will activate the sound.
If anyone could help me with that, I’d really appreciate it.
Try this:
void Update()
{
if (Input.anyKeyDown)
{
if (Input.GetMouseButtonDown(0)
|| Input.GetMouseButtonDown(1)
|| Input.GetMouseButtonDown(2))
return; //Do Nothing
// Play sound
}
}
if (Input.anyKeyDown) {
if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) {
return;
}
else {
// Do stuff.
}
}