Ubuntu has a menu entry which allows you to bind keyboard events to commands. I would assume that the action triggered by the power button would also be accessible from this menu.
Make a script called 'shutdown.sh' (or something) and put it in your home directory.
It's contents should simply be 'shutdown -h now'.
Run 'sudo chmod +x shutdown.sh' to make it executable.
In a terminal, run 'sudo nano /etc/sudoers', this is will open a text file for editing. Open it with a GUI text editor by replacing 'nano' with 'leafpad', 'gedit', etc. - whatever you have installed.
Add these lines to the end of the text file:
Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/halt, /sbin/reboot
<your username> ALL=(ALL) NOPASSWD: SHUTDOWN_CMDS
Obviously, replace '' with your actual username.
Save the changes you made (using Ctrl+o if you're using nano)
Finally, configure the power button to launch your script using the Ubuntu keyboard menu.
Like I said, I don;t use Unity so I am not sure of the exact procedure necessary to configure the power button to launch script, nor am I aware of the name of the key you will have to enter into the keyboard menu.
More information about editing the sudoers file can be found here: Ubuntu Sudoers