Move player to specific location and avoid obstacle.

Hello,

I need to move a player to many different location each time( the route not aligned), and avoid the obstacle.
i have try the code from this website :
Unity 3D - Enemy Obstacle Awareness - AI - Code Sample

but the player does not avoid obstacle and in some time go in another long route to arrive to the target.
should i use an algorithm for finding path?

Have you tried using NavMesh?

Assign the NavMesh Agent to your Character - then you have to bake the scene.
https://unity3d.com/learn/tutorials/modules/beginner/navigation/navmesh-agent
Check this link.

For your help, dodging the obstacles, try this, https://unity3d.com/learn/tutorials/modules/beginner/navigation/navmesh-obstacles?playlist=17105

Hope this helps.

In this Code last four if condition will remove.
Obstacle are remove it.