There are several distance measuring techniques like Infrared, Radio Wave (RADAR), Ultra Sonic Waves (SONAR), etc. Each of them have some advantages and disadvantages.
Most of the time, optical techniques are preferred for their high resolution, however they are not best suited for transparent objects. Optical performance is also limited in dusty environments. On the other hand, ultrasonic distance measurement perform much better in dusty environments or with transparent objects.
Comparing USPD with GP2D12 distance sensor, USPD can work in dusty enviroment, detect transperent/black objects, however may not be very efficient in detecting "Acoustically soft or damping" objects. USPD output is linear with distance and since it is low power device it can operate continuously.

mindsensors.com has developed an Ultrasonic Proximity detector with range of 30 cm to 2.5meters. This sensor is capable of detecting distances of objects in front with accuracy of 2-3 cm. Calibrated to directly read the distance in inches on RCX. i.e. reading of 40% on RCX means obstacle at 40 inches.

This sensor will work with MINDSTORMS NXT as a light sensor attached using converter cables supplied with MINDSTORMS Education NXT set.

How UltraSonic Proximity Detector worksUSPD has two ultrasonic sensors one is transmitter and other is receiver both are tuned to resonate at 24 kHz. Microcontroller inside USPD send burst of 24 kHz to transmitter. Then it times and listens for echo from the amplified output of the receiver. Since receiver is also tuned for 24 kHz it acts as 24 kHz band pass filter rejecting every thing else. Once microcontroller receives the echo in donain it calculate the distance of the object. Since it only Looks for the first echo, if there are more objects in front it would only detect the closest one.

How to connect Ultrasonic Sensor to RCX

If you are using standard lego wires, use the connector orientations as shown in this pitcure.

NQC users: set up your sensor as

SENSOR_TYPE_LIGHT
SENSOR_MODE_PERCENT

Probabilistic Localization with the RCX using Ultrasonic Proximity Detector
http://www.cs.hmc.edu/roboteducation/itcsl_RCXparticlefilteringWkshp.pdf

Probabilistic Localization with the RCX, by Lloyd Greenwald (with help from Babak Shirmohammadi**), Workshop materials prepared for Thinking Outside the (Desktop) Box, National Science Foundation Workshop, University of Mississippi, November 19-21, 2004.