I have drawn two platform one by one. and they are moving from right side of camera to left side. I want to place platform to right side of camera when goes out off left side of camera. so that I make a platform which is moving from right to left endlessly. How to do it?
transform.Translate(5,0,0);
Also see: Transform
You can check a game object’s screen position by doing this:
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Then you can simply do a check like this to see if the platform is beyond the left edge and move it:
if (pos.x < 0) {
transform.Translate(5f, 0f, 0f);
}
Now, you may have to add an offset to pos.x to make sure the platform is beyond the edge, since pos.x
is most likely not the right-most part of the platform. So, something like if (pos.x + 10f < 0)
.