- Home /
Moving a Object to position of a member of a list .
Hey guys. I am making a color game that I wanna player can drag and drop current color to a piece .for this I used this code .
foreach (var piece in Piece)
{
if (Vector2.Distance(CurrentColor.transform.position, piece.transform.position) < 1f &&
!CurrentColor.GetComponent<DragDrop>().dragging)
{
piece.layer = CurrentColor.layer;
CurrentColor.transform.position = Vector2.Lerp(CurrentColor.transform.position, piece.transform.position,
1f * Time.deltaTime);
}
}
my problem is when I ending drag if piece row is between 2 and 6, it moves to avg position of the two-piece. I attached an Image from my problem. what is wrong here? sry for my bad english.
[1]: /storage/temp/153920-new-text-document.png
new-text-document.png
(7.1 kB)
Comment
I'm guessing the problem is the Vector2.lerp, you probably don't want to lerp? Just set the position to a fixed position based on the background tile that your mouse currently is at?
Also your title of the question is very inaccurate based on what you're asking, it has nothing to do with a list.