How to moving 2D game object by touch in andriod system?
this my script :
public float speed = 4f, xBounds = 2.5f;
public Transform bulletPos;
public GameObject bullet;
void Start () {
StartCoroutine(Shoot());
}
void FixedUpdate () {
Movement();
}
void Movement()
{
float hor = speed * Time.deltaTime * Input.GetAxis("Horizontal");
float ver = speed * Time.deltaTime * 1f;
transform.Translate(new Vector2(hor, ver));
transform.position = new Vector2(Mathf.Clamp(transform.position.x, -xBounds, xBounds), transform.position.y);
}
IEnumerator Shoot()
{
Instantiate(bullet, bulletPos.position, Quaternion.identity);
yield return new WaitForSeconds(0.2f);
StartCoroutine(Shoot());
}
private void OnTriggerEnter2D(Collider2D target)
{
if(target.tag == "Enemy" || target.tag == "EnemyBullet")
{
Destroy(target.gameObject);
gameObject.SetActive(false);
}
}