Here is my code:
can anyone tell why is it showing me this error and how to fix it?
Vector3 targetPosition=new Vector3(hit.point.x,transform.position.y,hit.point.z);
It’s because you’re trying to change your position in the last line using Quaternion.Lerp and not Vector3.Lerp.
If you want to rotate your object smoothly you wanna use Quaternion.Lerp(transform.rotation, wantedRotation, rotationSpeed * Time.deltaTime).
For positions on the other hand you wanna use Vector3.Lerp and then the current position, the wanted position and the speed just like in Quaternion.Lerp, but with positions.