Rotating an object around Z axis using Lerp

I have spent a few hours going through different pieces of code and have been unable to find anything that limits the rotation to just one axis.

This is what I have so far… explanation to follow.

void Update(){
    i += (speed * Time.deltaTime);
    transform.rotation = Quaternion.Slerp(start, target, i);

    if (transform.rotation == target)
        i = 0f;
        gotTarget = false;


public void giveTarget(Vector3 pointIn){


gotTarget = true;
start = transform.rotation;

    Ray r = Camera.main.ScreenPointToRay(pointIn);
    point = r.origin;
    point.z = transform.position.z;

    target = Quaternion.LookRotation(point - transform.position);


the pointIn is mousePosition. transform.rotation == target is not working 100% at the moment.

the idea is when the object (a turret) is given an input, it will rotate around the Z to face the input position with its top (of a cylinder) smoothly using Lerp. when it reaches its final rotation, it will fire, then be ready for the next input.

however, the turret seems to be rotating through all angles in a peculiar way until.

i have uploaded a version to dropbox for the rotation to be seen. and you may see it not fire everytime as an if statement doesn’t always work.

any help appreciated

I found a solution to my problem on this forum page.
Just mentioning for other people searching for an answer to a similar problem.

Just use a Mathf.Lerp and only apply it to the Z axis:

   var r = transform.eulerAngles;
   transform.rotation = Quaternion.Euler(r.x, r.y, Mathf.LerpAngle(start, target, i));