Its not fungus ... its algae. Its basically a plant and uses exactly what your marijuana plants use to stay alive ... air, water and light. Fungus gnats love algae and lay their eggs in it. The eggs hatch into larvae, which in turn, eats the roots of your marijuana plants. Soooo ... the best bet is to stop the growth of the algae before the gnats find it. You can do that by blocking the light from hitting the tops of your pots and the soil. Use some white plastic, or something similar, cut to fit and put it over the soil. That will stop the algae growth post haste. Good luck.
Vi