Be aware of the child behind you before he or she touches your gun. If the hand approaches the firearm, use minimal force to brush the hand away, and sternly say, "Don't touch, please." (I put the "please" at the end because this is not a request. It is a politely phrased order.)
I would then look for the parents. Hopefully they are right there, have seen what happened, and are now responsibly dealing with the situation.
If the parents are not right there and handling the situation well, there are too many variables to come up with a single answer. It's a 40-page decision tree!