das420s
das420s

Reputation: 47

2d scrolling background effect

New to Unity, trying to recreate the scrolling background effect found in this asset pack but cannot find anything online. https://pixel-frog.itch.io/pixel-adventure-1.

Upvotes: 1

Views: 113

Answers (1)

bar9833625
bar9833625

Reputation: 321

You could just create a quad with the checkerboard pattern material on it and then change the texture offset programmatically.

I didn't actually test this code out but here's some code:

public class AnimatedBackground : MonoBehaviour
{

    public float scrollSpeed = 0.5f;
    
    private Material material;
    private float offset = 0.0f;

    void Start()
    {
        material = GetComponent<MeshRenderer>().sharedMaterial;
    }

    void Update()
    {
        offset += Time.deltaTime * scrollSpeed;
        material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
    }
}

Of course, if you want more than one checker then you can adjust the scale of the texture in the material properties.

Upvotes: 1

Related Questions