How does the crystal know where to stop stacking the unit cells? I tried to make different crystals in the cubic system by stacking cubes in a 3D software. However, I need to tell the software where to skip rows or stop stacking the unit cells in a specific direction else it will only make a cube.

How does this work in nature? How does the fluorite "know" where to skip rows in order to make the octahedron crystal? Does it have something to do with Bravais lattices and coordination numbers? 

First I thought that the unit cell needs to look like the final shape, but I think I'm wrong there.
The ideal crystal is terminated by planes, which are described by 
Miller Index. Some of these planes are more favorable than others, and as a result, the crystals do get macroscopic shape which is different from the shape of unit cell. For some discussion on reasons for different stability, I have found this article: iopscience.iop.org/0022-3719/12/22/036/pdf/jcv12i22p4977.pdf