unity movement movetowards code example
Example 1: movetowards unity
//put this in update method and disable rigidbody2d (gravity)
void Update()
{
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
Example 2: unity movetowards 2d
/// <summary>
/// Move 2D sprite towards target
/// </summary>
/// <param name="target"></param>
/// <param name="movementSpeed"></param>
private void Move(Vector3 target, float movementSpeed)
{
//Move
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}