Trying to make a void run continously at a interval (changeable by variable) while finger is held on screen
Hi Unity Answers, I've got a simple mobile game im working on in the style of galaga/space invaders, and im trying to make the ship fire continuously while the players finger is held down on the screen, with the fire rate modifiable with a variable. Currently I have this line here to detect when the finger is on the screen.
void OnMouseDrag()
{
Shoot();
}
And I've got this snippet of code to actually fire the ships laser cannons.
public void Shoot()
{
// shooting logic
Instantiate(laserPrefab, FirePoint1.position, FirePoint1.rotation);
Instantiate(laserPrefab, FirePoint2.position, FirePoint2.rotation);
}
I'm having trouble getting the shooting mechanism to loop while the finger is held on the screen, could anyone give me some advice? Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612225326im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cannot pick random GameObject from list. 0 Answers
Unity 2d android game How to "freeze" position on Y axis 1 Answer
Character Shooting Mechanic 2D Issues 0 Answers
Touchscreen Movement?? 1 Answer
Joystick + swipe question? 0 Answers