Question by
Genesis4545 · Feb 13, 2017 at 09:45 AM ·
backgroundscrollingparallax
2D scrolling background
Hi everyone! I'm currently trying to figure out a way to make my backgrounds scroll ONLY when the player is at a certain portion of the screen (right side). This is how I'm currently doing it:
void Update()
{
if (player.transform.position.x > 2)
{
float x = Mathf.Repeat(Time.time * scrollSpeed, 1);
Vector2 offset = new Vector2(x, savedOffset.y);
GetComponent<Renderer>().sharedMaterial.SetTextureOffset("_MainTex", offset);
}
}
Now the problem I'm having is that whenever I cross that line where the players position.x becomes >2 there's a slight sort of freeze. The game runs just fine but the background stays static for a split second then jumps forward ever so slightly and continues to scroll normally. It's like it starts scrolling just a little bit before I can actually see it scrolling, and so it looks like the backgrounds just jump forward a little bit. Is the code I'm using just too slow to keep up or?
Any help is greatly appreciated, thank you!
Comment