Get objects to move relative to background scrolling speed?

Hello, I have a scrolling background on a Quad. The background scrolling speed will eventually speed up overtime, as the player lives longer.

The game is essentially an endless runner, but the player never actually moves, so only the background will scroll to make it look like the player is moving. But because the player doesn’t move, I need to get the objects (like collectibles and hazards) to move at the same speed as the background, towards the player.

The script for the background scroll is :
using UnityEngine;
using System.Collections;

public class Scroll : MonoBehaviour
{
    public float Speed = 0.1f;

	// Use this for initialization
	void Start ()
    {
	
	}
	
	// Update is called once per frame
	void Update ()
    {
        Vector2 offset = new Vector2(Time.time * Speed, 0);
        GetComponent<Renderer>().material.mainTextureOffset = offset;
	}
}

and the script for the Object Movement is:

using UnityEngine;
using System.Collections;

public class ObjectMovement : MonoBehaviour
{
    public GameObject Background;

	// Use this for initialization
	void Start ()
    {
	}
	
	// Update is called once per frame
	void Update ()
    {
        Scroll scrollScript = Background.GetComponent<Scroll>();
        Debug.Log(scrollScript.Speed);
        GetComponent<Rigidbody2D>().transform.Translate(-scrollScript.Speed, 0, 0);
    }
}

So in the ObjectMovement script, I am trying to call the Background scroll speed, and then move the objects at that speed in the negative X direction, which is all working just fine.

The problem is that, no matter the speed of the background, the objects always move at the same speed. I could set the background to frozen, or moving super fast, and the objects always move at a constant speed.

If anyone could help with this, that would be really great.

Thanks! :smiley:

Edit: I got the objects to move at different speeds. But the objects move faster than the background. The object always move just a bit faster than the scrolling speed. No matter what the speed is set at.

I tackled this problem by using another quad for the object.
First, make the quad. It should stretch along the path you want it to take
Then, on the material play around with the tiling setting until your object looks right
Next, use the same code that you used with your background quad
Finally, you should be able to find a formula for the speed quite easily

Hope this helped!