- Home /
It's fixed
Audio to play with mouse axis.
I'm trying to put the last piece of the puzzle together for a door system. The AUDIO (the bane of my unity existence) I want a sound effect (door opening/ squeak) to play when the mouse axis is being moved. Here's what I've tried...
FirstI tried to use a simple if statement to say if the mouse axis was greater or less than .1, play the audio.
if(Input.GetAxis("Mouse X") > .1f || Input.GetAxis("Mouse X") < .1f)
{
audioSource[0].Play();
}
This just seemed to anger the unity gods and they refused to play any audio. So next I assigned the input to a float and clamped that sucker. Then simply play the audio when it's > || < than .1
This works! But, of course, it only stops if I reset the float to 0. The door system is a hold to grab and pull the mouse back/forwards to open so if I don't move the mouse but I have my button pressed the audio still plays...
I only want the audio to play when the player is pulling/pushing the door. I'm confident I could get it to work with mouse position but being a first-person game the cursor is locked to the center of the screen so that is ruled out.
Any ideas are greatly appreciated! Thanks.
Follow this Question
Related Questions
Dragging camera around object using mouse issue 0 Answers
How to make audio not playing repeatedly? 1 Answer
Toggle the Y axis Invert in MouseLook.cs with a keystroke? 3 Answers
How to stop audio 1 Answer
I can'^t move object in seceted axis 0 Answers