Auto hide all other apps when clicking on an app’s window
Assuming I understand your question correctly, you can do exactly what you want by holding the optioncommand keys down as you click on the window.

Also, if you just want to hide the last app (i.e. not all other apps) you can just hold down the option key while you click on the other window.