Raycast : Changing hit material back to its original transparency after the ray leaves it.

Currently in my game I have a shot out from that player that, on collision with an object sets its transparency to a certain amount. However, I need to allow the object to change back to its original un-transparent state once the ray leaves it. Any idea on how to do this?

shoot a ray constantly if the first object capable of the change was hit change and save it. as long as you raycast against it, do nothing anymore. the first time you hit nothing or something else, set it backand the saved reference to either a new changeable object or null.