Facing target, then shooting

i got a cannon with slow rotation speed (using Mathf.Lerp)

and this cannon firing even if not facing foe. I can’t say it something like

(if thisRotation == target.position)

//Fire

Lerp will never be right in needed position if target moving.
is there any way to say my tower start shooting only if target in some cone front of itself?

You can calculate the angle between your target and your cannon. So if the script is attached to the cannon it would be something like:

if (Vector3.Angle(transform.forward, foe.transform.position - transform.position) < some_angle) {
    // Start firing
}

Note that Vector3.Angle() returns an unsigned value.

This is what i have come up with, I know its a bit late but it helped me alot and I hope it helps others.

public bool CalculateAngle()
{
Vector3 targetDir = target.transform.position - gameObject.transform.position;
Vector3 up = gameObject.transform.up;
float angle = Vector3.Angle(targetDir, up);

    if (angle < 1f)
    {
        return true;
    }
    return false;
}