Moving an image on the X axis is not working as it should.
Hello I am making an endless runner game with a scrolling background.
I made this script:`
public float speed;
public float startX;
public float endX;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
if (transform.position.x < endX)
{
transform.position = new Vector2(startX, transform.position.y);
// print(transform.position);
}
}
that is supposed to move the image on the X axis and when it reaches a position, the image moves back to the beginning thus creating an infinite scrolling background.
My problem is that there are noticeable gaps in between my images like this one:https://prnt.sc/oe9fgy
I did all I knew. I reseted the positions, checked the images are cropped correctly, tried other images, but there is always a gap between them. Sometimes its bigger and sometimes the images overlap.
Help pls.
Your answer
Follow this Question
Related Questions
I need help for a mobile joystick 0 Answers
Get the Transform from Gameobjects in arrays to make a Line by Clicking the Mouse. 0 Answers
Doodle Jump Game Platform Spawn Issue Unity2D 0 Answers
How to check if class has RequireComponent on it? 1 Answer
How can I make the first image reappear when I return to the static pose? 0 Answers