Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help with <Renderer>.material.mainTextureOffset based on time.

Discussion in '2D' started by joplrw10, Aug 1, 2015.

  1. joplrw10

    joplrw10

    Joined:
    Aug 1, 2015
    Posts:
    5
    Using this thread, I am attempting to get a side scrolling picture constantly. Once the game has started, it renders the picture then lines as it moves right.

    Not sure what is going on. Any help is appreciated.

    public class ScrollScript : MonoBehaviour {
    public float speed = 0.25f;
    public Renderer rend ;
    // Use this for initialization
    void Start () {
    rend = GetComponent <Renderer>();
    }
    // Update is called once per frame
    void Update () {
    rend.material.mainTextureOffset = new Vector2 (Time.time*speed,0f);
    }
    }
     
  2. Zk

    Zk

    Joined:
    May 25, 2013
    Posts:
    19
    It seems to me like that should work. I created a script to do pretty much the exact same thing, and it worked fine when attached to an object with a texture renderer. Are you getting any errors?

    Here's my script:

    Code (CSharp):
    1. public class TextureScroll : MonoBehaviour
    2. {
    3.  
    4.  public float horizontalScrollSpeed = 1f;
    5.  public float verticalScrollSpeed = 0f;
    6.  Renderer myRenderer;
    7.  
    8.  void Start ()
    9.  {
    10.   myRenderer = GetComponent<Renderer> ();
    11.  }
    12.  
    13.  void Update ()
    14.  {
    15.   myRenderer.material.mainTextureOffset = new Vector2 (Time.time * horizontalScrollSpeed, Time.time * verticalScrollSpeed);
    16.  }
    17. }
     
  3. joplrw10

    joplrw10

    Joined:
    Aug 1, 2015
    Posts:
    5
    Figured it out. Under Inspector for the texture itself, the render setting had to be under Wrap.

    Thank you though!