Living creatures have been able to tell if it’s light out or not for about two billion years. That’s when some eukaryote cells evolved to be able to sense changes in their surroundings and react to them.
These eyespots continued into animals with more than one cell. Flatworms, which evolved around 550 million years ago, also have eyespots. But a flatworm doesn’t waste energy building an eyespot in every cell. Instead, it has just two eyespots in its head. These eyespots, though, are already bilaterally symmetrical and are placed in about the same place as your eyes, and for the same reason – so that the flatworm can see where it is going before it gets there.
Sometime after that, some animals evolved eyespots that were sunken a little bit into the head, instead of level with the surface. Maybe this helped to protect the eyespots so they didn’t get damaged. But it happens that sinking the eyespots into a hole also helps to focus the light, which let these animals see better than their ancestors.
Once animals like roundworms began to use the hollow to focus the light, about 548 million years ago, they evolved ways to focus the light better – the holes became deeper, and the opening smaller, so they worked the same way a pinhole camera does.
By around 542 million years ago, the arthropods (insects and crabs) had an early form of eyes. Over time, these and many other types of creatures evolved lenses. They also evolved the muscles to move their eyes from side to side. Eyes come in a lot of different kinds, so animals must have evolved eyes separately many different times in different ways.
Early mammals seem to have actually developed less good eyes than the reptiles had, because these mammals were awake mainly at night and slept during the day, as moles do now. Some other creatures, like deep sea fish, actually evolved to not even have eyes anymore, because it was always dark where they lived.
But after the dinosaurs died off, mammals began to take over daytime as well as night-time. Different mammals developed different eyes according to what would be most useful for them. Humans evolved to have both of our eyes in the front of our face.
We don’t see as much on our sides or in back of us, but we can tell easily how far away something is, by using binocular vision. We see slightly different views of the world from each eye (try closing first one eye and then the other). Putting them together, our brains can judge how far away something is from us. (Try walking around with only one eye open and see how hard it is to judge distance.) Some people think that human eyes may have evolved specially to let us see dangerous snakes, which evolved about the same time as humans did.