- Home /
How to create a shoot button for touch GUI
I'm trying to create a GUI button for shooting. The player places their finger on that area and it should auto-fire until they don't touch that area.
Using a gui button doesn't work. For one thing the button only responds when you lift your finger so you have to tap it a repeatedly. Also, if you touch the screen anywhere else the button won't respond (if you want to move the character with the joystick, etc.).
What solution should I pursue?
This is what I got so far:
I'm creating a rectangle area and then see if it's being touched. As long as it's touched it's going to run the shoot function.
It doesn't work as I got the syntax quite wrong, but am I even close?... :-/
Rect rectButton1 = new Rect(Screen.width / 1 - 175 / 1,
Screen.height /1 - 175 /1,175, 175);
void OnUpdate() { if ( rectButton1.Contains(Input.GetTouch)) Shoot(); }
Answer by 9900 · Apr 10, 2016 at 10:05 AM
Better use OnGUI OnGUI () { If (GUI.RepeatButton (Rect (10, 10, 70,100) { Shoot (); }}
Your answer
Follow this Question
Related Questions
GUI.Button Touch Input Problem 1 Answer
Mouse and Oculus Touch Controller Inputs 0 Answers
Touch not working on guiTexture. 1 Answer
Distribute terrain in zones 3 Answers