I have a top down shooter where I want the position of the player to affect how fast the ground texture is scrolling on the object below them. While I could get it work while there is no player input, while the player is actively moving, the texture speeds up very fast (when going + Z) and goes backwards (when going - Z). I cannot figure out why it is doing this and what the workaround is
using UnityEngine;
using System.Collections;
public class ScrollTexture : MonoBehaviour {
public float scrollSpeed=.01f;
public GameObject modifier;
public Renderer rend;
private float modifiedSpeed;
// Update is called once per frame
void FixedUpdate () {
modifier = GameObject.FindGameObjectWithTag("Player");
modifiedSpeed = ((modifier.transform.position.z + 6.0f) / 50.0f);
float speed = scrollSpeed + modifiedSpeed;
float offset = Time.time * speed;
rend.material.SetTextureOffset ("_MainTex", new Vector2 (0, offset));
}
}