The script doesn't work

The script doesn’t work. more precisely a srypt for infinite road scrolling Does anyone know where is some error ??? Here is the script

using UnityEngine;
using System.Collections;
public class RoadInfiniteScrolling : MonoBehaviour
{
public float scrollSpeed;
private Vector2 offset;
void Update()
{
offset = new Vector2(0, Time.time * scrollSpeed);
GetComponent().material.mainTextureOffset = offset;
}
}

I’ve no idea what exactly you wanna do. It throws some error? Just the offset seems to not change? Plz be more precise with the info you give to us.
PD: Not a good idea to GetComponent each update.

using UnityEngine;
using System.Collections;
public class RoadInfiniteScrolling : MonoBehaviour
{
    public float scrollSpeed;
    private Vector2 offset;
    Renderer rend;

    void Awake()
    {
        rend = GetComponent<Renderer>();
    }

    void Update()
    {
        offset = new Vector2(0, Time.time * scrollSpeed);
        rend.material.mainTextureOffset = offset;
    }
}
1 Like

Thanks this script work.