- Home /
How can I move tiles that are off the screen in unison?
I have 3 background tiles that are the same size as the screen. They are stacked vertically. I want the position of the tiles to go from ABC to BCA vertically. where A remains the tile in the middle of the screen. I wrote this function:
public void MoveUnseenToTop() {
foreach (SpriteRenderer tile in tilesVertical) {
if (!tile.isVisible && tile.transform.position.y < 0) {
tile.transform.Translate(Vector3.up * backgroundHeight);
}
}
}
Were 0 is the middle of the screen and backgroundHeight is the height of all tiles combined. The function work properly with a set of 2 tiles. But once the tile count increases the tile closest to the screen moves further than all the other tiles. (resulting in something that looks like B___CA) Is this a bug in my code or Unity? I'm using Unity version 2019.4.1f1
Your answer
Follow this Question
Related Questions
How do I get the collider working when I do transform. 1 Answer
How to create animated tile that plays only once 0 Answers
Problems with do-while loops and IEnumerator 1 Answer
Interchangeable value loop 1 Answer
Auto tile texture 1 Answer