My tweak to the scrolling background

I made rawInput public and used it to make the background move with the Player

using UnityEngine;
using UnityEngine.SceneManagement;
public class SpriteScroller : MonoBehaviour
{
    [SerializeField] Vector2 moveSpeed;
    Vector2 offset;
    Material material;
    void Awake()
    {
        material = GetComponent<SpriteRenderer>().material;
    }

    void Update()
    {
        if (SceneManager.GetActiveScene().buildIndex == 1)
        {
        offset = moveSpeed * Time.deltaTime * FindObjectOfType<Player>().rawInput;
        }
        else 
        {
            offset = moveSpeed * Time.deltaTime;
        }
        material.mainTextureOffset += offset;
    }
}

Edit: Updated to support other Scenes.

Privacy & Terms