using UnityEngine;
using System.Collections;

public class Touch_move : MonoBehaviour {
	public GameObject player;
	public Vector3 pos;
	public float speed;

	// Use this for initialization
	void Start () {
		pos = player.transform.position;
		}

	void FixedUpdate(){

		if (Input.touchCount == 1) {

			if (Input.GetTouch (0).tapCount == 1) {
				speed = 0.06f;
				Ray ray;
				ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);

				RaycastHit hit;

				if(Physics.Raycast(ray,out hit)){

					print (hit.point);

					if (hit.point.x < player.transform.position.x) {


						pos = new Vector3 (hit.point.x + 2, pos.y, pos.z);
					} else {

						pos = new Vector3 (hit.point.x - 2, pos.y, pos.z);
					}


					if (player.transform.position.x > pos.x) {

						player.transform.localScale = new Vector3 (-1.5970f, player.transform.localScale.y, player.transform.localScale.z);

					} else {

						player.transform.localScale = new Vector3 (1.5970f, player.transform.localScale.y, player.transform.localScale.z);
					}

				}



			}
			if (Input.GetTouch (0).tapCount == 2) {

				speed =0.16f;

				Ray ray;
				ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);

				RaycastHit hit;

				if(Physics.Raycast(ray,out hit)){

					print (hit.point);

					if (hit.point.x < player.transform.position.x) {


						pos = new Vector3 (hit.point.x + 2, pos.y, pos.z);
					} else {

						pos = new Vector3 (hit.point.x - 2, pos.y, pos.z);
					}


					if (player.transform.position.x > pos.x) {

						player.transform.localScale = new Vector3 (-1.5970f, player.transform.localScale.y, player.transform.localScale.z);

					} else {

						player.transform.localScale = new Vector3 (1.5970f, player.transform.localScale.y, player.transform.localScale.z);
					}

				}

			}

		}

		player.transform.position = Vector3.MoveTowards (player.transform.position, pos, speed);

	}
	// Update is called once per frame
	void Update () {

		print (Time.fixedDeltaTime);

	}
}
