[SOLVED] How does the "mouseUp" function work

I’m making a first-person shooter game and I decided to make an automatic rifle that shoots bullets while you hold the left mouse button and stops once you release it. I’ve found that “mouseDown” works and the gun shoots, but it never stops shooting, and “mouseUp” seems to have no effect. I’m wondering if I’m using “mouseUp” wrong or if there’s an issue with my code. I’d appreciate it if someone can explain to me how “mouseUp” works and give me input on how to fix my AR.

Hi @Glast and welcome! It seems like you are missing the mouse up event in the initialize function.

1 Like

How would that work? Can you tell me how to properly initialize it, please? Thank you.

On line 52 of your script, you have the event for mouse down. You can add the event below for mouse up.

this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);

Thank you, I’ll try this.

It worked, thank you so much! I can’t believe I missed something so simple and spent hours pondering what I was doing wrong. Thanks for your help.

1 Like