when user taps 1 touch screen it should move once but when I touch and hold the screen down it keep moving a lot
I just want the 1 tap 1 move feature for the touch button not 1 tap and hold and keeps moving
so if player taps 1once and holds on that 1 tap it will only move once
at the moment this code keeps jumping on tap hold down
please help
android game
2d game
using UnityEngine;
using System.Collections;
public class Toucht : MonoBehaviour
{
public float upForce;
public float downForce;
public float forwardSpeed;
public bool isDead = false;
Animator anim;
bool flap = false;
void Start()
{
anim = GetComponent<Animator> ();
GetComponent<Rigidbody2D>().velocity = new Vector2 (forwardSpeed, 0);
}
void Update()
{
if (isDead)
return;
Touch myTouch = Input.GetTouch(0);
Touch[] myTouches = Input.touches;
for(int i = 0; i < Input.touchCount; i++)
flap = true;
}
void FixedUpdate()
{
if (flap)
{
flap = false;
anim.SetTrigger ("Flap");
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, upForce));
}
if (Input.GetKeyDown("t"))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, 0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (-0, downForce));
}
}
int hit = 0;
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag == "Wall")
{
hit++;
if(hit >= 25)
Destroy(gameObject);
}
if(other.gameObject.tag == "Wall")
{
GetComponent<AudioSource>().Play();
}
}
}