using UnityEngine;
using System.Collections;

public class Paddle : MonoBehaviour 
{
    public float moveSpeed = 20.0f;
	public float maxPaddleX = 16.0f;
		
	void FixedUpdate () 
	{
		float moveInput = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
		transform.position = transform.position + new Vector3(moveInput, 0f, 0f);
		
		if (transform.position.x <= -maxPaddleX || transform.position.x >= maxPaddleX)
		{
			float xPos = Mathf.Clamp(transform.position.x, -maxPaddleX, maxPaddleX); 
			transform.position = new Vector3(xPos, transform.position.y, transform.position.z);
		}

		if(Input.touchCount > 0)
		{
			Vector3 touchPosition = Input.GetTouch(0).position;
			touchPosition.z = transform.position.z*1.2f;
			Vector3 touchPositionWorld = Camera.main.ScreenToWorldPoint(touchPosition);
			transform.position = new Vector3(-touchPositionWorld.x, transform.position.y, transform.position.z);
		}
	}
}
