stop object rotating (using transform.Rotate) through another object

Hi all i am a newbie here (and with Unity). Currently creating a crane arm and cant stop the arm rotating through terrain and other objects, have tried colliders but no good results - any ideas please.

One solution would be to add two trigger colliders for both side of the crane. Then write script like: void on right trigger enter gameobject other { bool right = false}. Void on right trigger exit {gameobject other right = true} Same to left collider. Then add your main script:“if right == true {you can rotate crane to right}”. Now your crane should stop before going too deep to something solid(which have collider). (Btw that isnt working script. just explain what should it look like). Trigger collider script example: Unity - Scripting API: MonoBehaviour.OnTriggerEnter(Collider)
Sorry cant write complete script right now. I might be able to write and post complete script in few days.