Transform.rotate to mouse point

I have a mouse point, Vector3 Target and an object that rotates to the mouse down point.
My object rotates on z axis only.

I tried

Target = new Vector3 (0f, 0f, Target.z)
Transform.Rotate (Target)

But on every mouse down, the object rotates clockwise, clockwise and clockwise.
How do I make the object rotates to look at the mouse point directly?

Thanks in advance!

Firstly you probably want to convert the mouse position to a world position. You can do this with Camera.ScreenToWorldPoint.

Transform.Rotate will rotate by a given angle, not towards a target. That’s why it’s always rotating one direction. Vector3.RotateTowards should do what you describe. You can pretty much copy the example from the documentation.

public float speed;

void Update() {
  if (Input.GetMouseButtonDown(0)) {
    Vector3 target = new Vector3(0, 0, Camera.main.ScreenToWorldPoint(Input.mousePosition).z);    
    Vector3 targetDir = target - transform.position;
    float step = speed * Time.deltaTime;
    Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
    transform.rotation = Quaternion.LookRotation(newDir);
  }
}