Diferent way to move a oject?

Hello!

With my actual scrip my object is following the mouse when the botton is clicked, but i want make the object go to a determinated posision when i click the mouse button, how can i do it?

that is my actual script

public float moveSpeed = 2.0f;  // Units per second

void Update () {
	if (Input.GetMouseButton(0)) {
		var targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		targetPos.z = transform.position.z;
		transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
	}
}

}

The very basic logic here is to get the mouse position when the mouse is clicked then store it in a variable. After that you just set the game object to move in that position. Here is a very easy implementation which can get you started with the movement logic you require:

public class PlayerController : MonoBehaviour
{
    public float speed = 2f;

    private Vector3 m_movePosition = Vector3.zero;
    private bool m_move = false;

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            m_move = true;
            m_movePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }

        if (m_move == true)
        {
            transform.position = Vector3.MoveTowards(transform.position, m_movePosition, Time.deltaTime * speed);
        }
  
    }
}

However in my opinion this can be used only for very basic(for instance a game prototype) and educational purposes and i would say you should use coroutines to perform that sort of stuff(moving from one position/rotation/scale/value to another). Coroutines can be difficult to grasp at first , but when you get use to them you will have the power to update your code only when you demand it(for instance when a certain event triggers) and stop using conditional checks in the Update() which in a complex controller scenario can be difficult to read and lead easier to bugs.

set targetPos to the position you want it to go to. Right now you are setting it to the mousePosition.