using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed;
    private Vector2 target;

    // Update is called once per frame
    void Update()
    {
		Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

		//Check if the user left clicks and if they do get the coordinates of where they clicked
		if (Input.GetMouseButtonDown(0))
        {
            target = new Vector2(mousePos.x, transform.position.y);
		}
		//Move the player towards the target coordinates
		transform.position = Vector2.MoveTowards(transform.position, target, Time.deltaTime * speed);
    }
}
