Yes, so long as it's not code from a paid asset. I use code from Stack Overflow / Unity Answers all the time, modified to work in my game of course.
so can I use code from a past project?
Yes.
OK thanks