I’m making a mobile game, that has a jump button and a tap to shoot system. My problem is that whenever you click the jump button on screen, the player will shoot at it, causing them to suffer delay, which makes a jump shoot maneuver not really work.
Here’s the code for shooting:
void Update()
{
if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Began) {
if (Time.time > shotStart + shotCooldown)
{
anim.SetTrigger("Shooting");
Vector2 touchPos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 dir = touchPos - (new Vector2(transform.position.x, transform.position.y));
dir.Normalize ();
GameObject bullet = Instantiate (bomb, transform.position, Quaternion.identity)as GameObject;
bullet.GetComponent<Rigidbody2D> ().velocity = dir * bulletSpeed;
shotStart = Time.time;
}
}
Thanks in advance~