Position Sensor help

Hello community,
I have a question about how to track position of an object. This is an interesting one because it’s a fuel level gauge. It’s one that mounts to a tank and is visible through a plastic tube. The tube is approx 4” tall and .75” dia and has a round plastic indicaticator that travels up and down approx 3” in total to indicate fuel level.

I was thinking of using a couple photocells and LED to measure light position...?!? As the plastic indicator passes from top to bottom I may be able to get a consistent light pattern that I can write code for.... Not sure.. also amibient light could affect the photocells too much...

However, there maybe there is some kind of proximity sensor that may work?!

Any advice, thanks all!

A number of LEDs on one side; and a lot of LDRs on the other side. Shield the LDRs so they don't pick up (much) ambient light.
The more LDRs the more steps you have.
If the floater has a magnet attached, you could do the same with an array of reed switches or hall effect sensors.