look at object only on y axis with rotation limit

hey guys , so i’m using a script to make my object look at the target only on y axis. is there any way to limit the object’s rotation? for example rotate on y axis only 45 and -45 degrees thanks
public class lookonlyony : MonoBehaviour {
public GameObject target;

	// Use this for initialization
	void Start () {
		
	}

	// Update is called once per frame
	void Update () {



		Vector3 targetPosition = new Vector3 (target.transform.position.x,transform.position.y, target.transform.position.z);
		transform.LookAt (targetPosition);
	}
}

Hello,

You may take a look at the Mathf.Clamp function :

This function limit a value between a Min and a Max.

Is it what you are looking for ?