How can I move object smoothly if collision occurs?

The first thing any basic 2D physics show you is that the only thing that moves in 2D physics is a Rigidbody2D and you use the API it provides. You should never ever modify the Transform, that’s what the Rigidbody2D does so you’re bypassing physics.

Also, you cannot do what you’re doing above as entering into a loop like that will stall the main thread completely until it exits the loop. This suggest some basic misunderstanding of how things work so I would advise you follow some tutorials on this stuff before proceeding. It’s far more enjoyable than guessing how things work and a lot less frustrating.

FYI: Here’s how to post code on the forums: Using code tags properly

Good Luck.