Aplique os seus conhecimentos de algebraálgebra:
x + y = x + (1)*y
x - y = x + (-1)*y
Crie um método novo método e coloque esse código repetido nele, use aquele que tem o sinal +
e multiplique o troço (initialMousePosition.y - mousePosition3D.y)
pelo valor passado ao método.
Chame esse método passando 1 ou - 1 consoante queira somar ou subtrair.
private void SwipeContainer(Directions direction){
if(direction == Directions.Top && transform.localPosition.y < maxTopPosition){
movimenta(1);
}else if(direction == Directions.Bottom && transform.localPosition.y > maxBottomPosition){
movimenta(-1);
}
}
private void movimenta(int direcao){
Vector3 position = Input.mousePosition;
Vector3 mousePosition3D = Camera.main.ScreenToWorldPoint(position);
mousePosition3D.z = -1f;
mousePosition3D.x = transform.position.x;
mousePosition3D.y = transform.position.y + direcao * (initialMousePosition.y - mousePosition3D.y);
transform.position = Vector3.MoveTowards(
transform.position, mousePosition3D, speedMoviment * Time.deltaTime
);
}