I have a tray of objects at the bottom of the screen starting from 150px on X screenspace that are ordered in a list from left to right, what I’m trying to do is when one of the objects is removed from the tray and the list, move all objects to the right/lower on the list 250px to the left to fill in the space left by the removed object. With my code right now, all the objects are moving to the left with the first object being at the start of the tray(150px), when they should only move over to the left 250px from their current position. I get the position of the removed piece in one function with
selectedPos = Camera.main.ScreenToWorldPoint(selectedPiece.transform.position);
then try to move all the pieces over 250px to the left with
void RemoveFromTray(GameObject p)
{
for (int i = 0; i < pieceTray.Count; i++)
{
if (pieceTray[i].gameObject == selectedPiece)
{
removedPieceIndex = i;
}
}
pieceTray.Remove(p);
float spacing = 150;
for (int i = removedPieceIndex; i < pieceTray.Count; i++)
{
GameObject piece = pieceTray[i];
Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(selectedPos.x + spacing, 0 + 175, 10));
Debug.Log(newPos);
piece.transform.DOMove(new Vector3(newPos.x, piece.transform.position.y, piece.transform.position.z), 0.5f);
spacing += 250;
}
}
Not sure why it’s not taking the selectedPos.x into account and using that as the start point, it instead is just using the 150px as the start point for all moved objects. Any help would be appreciated, thanks.