Endless Falling Background that is affected by players screen position.

I was wondering if anyone had any suggestions on how to go about this. I have an endless falling game I am trying to do and I want to have the background scrolling constantly while the player is on screen. That part is no problem, the part I want to have and am having a problem with is I want to slow the background down when the players position is increased in the “Y” axis and speed up when the position is decreased. The player isn’t really falling with a rigidbody2D which is why i am having trouble with this. I have the gravity set to zero and I am just trying to move the background with the Material Offset. If anyone has any ideas please let me know. Thanks!

something like this?

    using UnityEngine;
    using System.Collections;

    public class ScrollBackground: MonoBehaviour {

              public float scrollSpeed = 0.1f;  // speed multiplier, to audjust speed.
              public GameObject player;

               void Start() {

                   if (player == null)
                        player = GameObject.FindWithTag("Player");
               }

                void Update () {

                   float offset = (Time.time * scrollSpeed) / player.transform.position.y;
                   renderer.material.SetTextureOffset ("_MainTex", Vector2(offset, 0.0f));
               }
    }

Attach this script to your background object. You can set the default speed with “scrollSpeed” in the inspector.
You can add your player in the inspector, too. Or the code will find your player, if the player is tagged to “Player”.
If you want change horizontal/vertical scrolling just excange offset and 0.0f in the last line.

It´s only an idea to show, how to scroll the texture of a material (in this case the Main_Texture) with variable speed.

Thanks for replying, I had most of what you put thanks to the docs, but the addition definitely got me started. I had to change the division to subtraction and it works more to what I needed. Then after everything was done I had to divide the final offset by 4. Thanks again for the reply now I just have to figure out how to smooth the background when I move up in the “Y”. I will post I code I have now for anyone in the future who wants to see it.

using UnityEngine;
using System.Collections;

public class BackGroundScroll : MonoBehaviour {
	
	public float scrollSpeed = 2.0f;
	public GameObject player;

	void Start()
	{
		player = GameObject.FindWithTag("Player");
	}

	// Update is called once per frame
	void Update () 
	{
		float offset = scrollSpeed * Time.time - player.transform.position.y;
		renderer.material.mainTextureOffset = new Vector2 (0, -offset/4);
	}
}

There is /player.transform.position.y to slow down the scroll speed if you move up in Y axis.

If you not use the transform to move your player, use the Y coordinate value of your movement script instead of player.transform.position.y

The subtraction I changed out for the division seemed to work better than the divide for what i wanted. Also when I added your changes to my original script(it then became your script that you posted basically), at Runtime the background was so severely stretched it was one color, at least until I moved my player. I am just curious as to why that happened. But everything is working well, so thanks for your help!