playMaker

Author Topic: Rapid fire using GUI button [Solved]  (Read 2347 times)

jayf

  • Playmaker Newbie
  • *
  • Posts: 40
Rapid fire using GUI button [Solved]
« on: May 17, 2014, 10:25:36 AM »
Hi.
I'm trying to make a gun shoot while I'm pressing down on the button. The FSM setup is simple enough (thought I'd upload a screenshot to show my exact setup :) ): It starts out "Waiting", after the button is pressed, send the "Fire" event. If the button is not pressed, go back to "Waiting". 
Problem is, it only shoots once eventhough my finger is still on the button. Is there a way to loop the command or tell the FSM to keep sending the event until I take off my finger?


« Last Edit: May 20, 2014, 11:05:44 AM by jayf »

Lostcity

  • Playmaker Newbie
  • *
  • Posts: 31
Re: Rapid fire using GUI button
« Reply #1 on: May 17, 2014, 02:27:38 PM »
I'm using a GUI Texture as my touch button instead of a GUI button, but I'm sure it works pretty similar. Here is how mine is set up (though there are probably many ways to do this): 

Step 1: Create a new Bool Variable. Lets call it TouchStatus.

State 1: Touch GUI event. (make transition to state 2)

State 2: GUI Element hit test (hit event: Fire, Store result in your TouchStatus Bool). I also have a Wait action set up that simulates my rapid fire speed. You can also add shoot sounds, muzzle fire, or bullets to this state by using a Create Object action. (make transition to State 3)

State 3: Bool Test action. This will test if your player is still touching the fire button. Use the TouchStatus bool as the Bool variable. Create a transition that loops back to State 2.

This is the core of getting a rapid fire gun. Once you get this set up its fairly easy to set up an Ammo display and reload action.

Again, I'm using a GUI Texture as my fire button, so you may have to change a few actions (or not) but this should get you started. I hope this helps.


jayf

  • Playmaker Newbie
  • *
  • Posts: 40
Re: Rapid fire using GUI button
« Reply #2 on: May 20, 2014, 11:05:20 AM »
Thanks it works! The part where I needed to store the touch info as a Bool was what I needed to make it work.