- Home /
Question by
Charlie010903 · Apr 11, 2020 at 08:19 PM ·
shootingjoystickmobile devicestouches
How do I change this code so that i can press on the joystick more than once to shoot?
I get this error when i try to shoot using my joyatick: ArgumentException: Index out of bounds. UnityEngine.Input.GetTouch (System.Int32 index) <0x37332080 + 0x00092> in :0 ShootingPrefab.Update () (at Assets/C# code/ShootingPrefab.cs:25)
This is my code: if (Input.touchCount > 0) { Touch t = Input.GetTouch(1); if (t.position.x > Screen.width / 2 && shootCooldown < 0) {
Shoot();
}
}
Comment
Answer by Charlie010903 · Apr 11, 2020 at 08:20 PM
void Update() {
if (shootCooldown > 0)
{
shootCooldown -= Time.deltaTime;
}
if (Input.touchCount > 0) {
Touch t = Input.GetTouch(1);
if (t.position.x > Screen.width / 2 && shootCooldown < 0)
{
Shoot();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612231139im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Alternative to OnMouseDown() 2 Answers
Crossplatform Joystick cicular movement instead of square? 2 Answers
EventSystem.IsPointerOverGameObject doesn't work on virtual joystick (mobile) 0 Answers
While I'm using joystick I also touching screen how can I fix it ? 0 Answers
Fenerax's Joystick problem 0 Answers