The field and angular dependence of critical current densities J(c) in laser ablated YBCO thin films, deposited on MgO, are investigated. Contributions of intrinsic pinning, due to the layer structure of the crystal, and of pinning due to defects are identified. It is shown that the pinning mechanism due to the crystal structure is temperature dependent and that a transition from a 2D superconducting state at low temperatures to a 3D state at high temperatures occurs. In addition, systematic studies reveal small differences in J(c) (H parallel-to c) for films from different batches, if they are prepared under nominally identical production conditions, but large differences, if the deposition temperature is lowered only slightly.