Hi there,
I have the following code that I am using for a background that I want to scroll left and right, repeating. Unfortunately, I am getting a gap between the objects… sometimes it overlaps, other times there is the gap… is there any more precise way to scroll two objects as one?
private var fLeftPosition = -21.07282;
private var fRightPosition = 21.07282;
function Update ()
{
transform.localPosition.z = 5.785643; // Locks the Z position
// When reaches left limit, reset position
if (transform.localPosition.x < (fLeftPosition * 2))
{
transform.localPosition.x = (fRightPosition * 2);
}
// When reaches right limit, reset position
else if (transform.localPosition.x > (fRightPosition * 2))
{
transform.localPosition.x = (fLeftPosition * 2);
}
// Move background when turning left and right
if (PlayerControl.g_bPlayerOneIsTurningLeft == true)
{
transform.Translate((-PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
}
else if (PlayerControl.g_bPlayerOneIsTurningRight == true)
{
transform.Translate((PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
}
else
{
transform.Translate(0, 0, 0);
}
}