Ask if you can.
If you can't, ask someone else who has if they did. If they did, it's almost certainly okay.
Credit if you know.
If there is a license, follow it.
Credit changes in the credits.
But ultimately, if it feels wrong, don't do it.
--
edit: Unless the code is noted otherwise, anyone can have any code I've ever touched. Even if we don't get along, I don't care. It's code, not part of my identity, and I'd rather games be enjoyable for those who run and play it than someone massaging my ego.
Actually that's a trick, my code helping anyone enjoy a game massages my ego. I'm honored by anyone who wants to use it.