Where am i going wrong with my repeating background?
Hey, I learned a lot from the unity flappy bird style tutorial so as my first try at a game i was of course kind of making a clone.
The problem I just ran into was the sprites i used for the ground. The tutorial had a single large sprite which fit just right at the bottom but my sprite was smaller. It takes 6 duplicates to cover the same area.
At first i had a box collider for each sprite then i removed all colliders except one and stretched it to fit over all the sprites. Seemed like it should work but when it goes to repeat the background its off badly. I can see blue screen behind my character instead of the smooth seamless effect i got with the tutorial assets.
so this is the repeating script im using:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class RepeatingBackground : MonoBehaviour {
private BoxCollider2D groundCollider;
private float groundHorizontalLength;
// Use this for initialization
void Start ()
{
groundCollider = GetComponent<BoxCollider2D> ();
groundHorizontalLength = groundCollider.size.x;
}
// Update is called once per frame
void Update ()
{
if (transform.position.x < -groundHorizontalLength)
{
RepositionBackground ();
}
}
private void RepositionBackground()
{
Vector2 groundOffset = new Vector2 (groundHorizontalLength * 2f, 0);
transform.position = (Vector2)transform.position + groundOffset;
}
}
not sure where im going wrong. The method of stretching the box collider over all the ground sprites seemed like it shouldve worked.
Any tips would be appreciated. thanks included a quick pic of my bottom ground