Chemical communication... stop thinking like everything's human and consider while we have eyes as our thing, even our buddies the dogs use their noses more and have a whole sensory world we can't access or even imagine with our inferior snouts. Snails are complex survivors, and they are aware of their surroundings. How that works is something we don't know well. They have predators, and they have defences. They're just as evolved to survive in their world as we are for ours.
Your fish have a sense we don't - an exposed nerve along their flanks called the lateral line. It picks ups vibrations and movements as an early warning system. Tap the glass, and the impacts probably cause pain. It's right in front of our noses, but we generally don't even see it.
I have some Epiplatys killies with what may be a third eye light sensor on top of their heads - maybe a bird spotter. It seems to work like that.
Bladder snails eat fish eggs (ramshorns generally don't, btw). There is research that suggests many species of fish have eggs with chemical defences. They interact with the environment as eggs, and fight off predators. It starts before they're fish, in some cases.
Everything alive is complex. There are wonders in that fishtank even our phones can't fathom.