Set max angle rotation

Hey guys, I tried to see a lot of posts in unity answer but i dont found a resolution, so, i’m posting my question here.

I done a npc (like a panzer) and it have a max angle to aim in me, I’m with problem in the code. Its only one like i think =p

private void ChasePlayer()
        {

            Vector3 distPlayer = target.position - transform.position;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(distPlayer), Time.deltaTime * rotVel);
            transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);

            if (transform.eulerAngles.z >= 20)
            {
                eulerAngles.z = 20; <--- this is what i wanna do, lock the max angle
               
             }
        
        }

My clairvoyance senses just kicked in. In C# you cnanot change individual components such as x/y/z of transforms, you have to assign the whole Vector3. So use this:

private void ChasePlayer()
    {

        Vector3 distPlayer = target.position - transform.position;
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(distPlayer), Time.deltaTime * rotVel);
        float zAngle=transform.eulerAngles.z;
        if (zAngle > 20 && zAngle<=180)
        {
            zAngle = 20;
        }
        else if (zAngle < 340 && zAngle>180)
        {
            zAngle = 340;
        }            
        transform.eulerAngles = new Vector3(0, 0, zAngle);
    }