Search Unity

uv offset for line Renderer.

Discussion in 'Scripting' started by cDixRun, Mar 31, 2010.

  1. cDixRun

    cDixRun

    Joined:
    Jun 22, 2009
    Posts:
    39
    For Starters, I am an Artist above all else, I am just learning the JavaScript side of Unity.

    I have a line renderer attached (as a component) to a cube and I am trying to offset the UV coordinates via the following code. The script is attached to the Unity Cube:
    Code (csharp):
    1. // Scroll main texture based on time
    2.  
    3. var scrollSpeed = 0.1;
    4. function Update ()
    5. {
    6.     var offset = Time.time * scrollSpeed;
    7.  
    8.     GetComponent(LineRenderer).material.SetTextureOffset ("_MainText", Vector2(offset/10.0, offset));
    9. }
    Currently; I do not have any compile-time errors and no run-time errors either, but nothing happens.

    My end result should be a scrolling line renderer material with a non scrolling cube material.

    P.S. This script has been modified from the Unity Sewer-demo Scene.

    I appreciate all help/tips in advance.

    ~cDixRun
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The property name for the main texture is usually _MainTex, not _MainText. If there isn't a property called _MainText, that would explain why your code compiles but still doesn't work.
     
  3. cDixRun

    cDixRun

    Joined:
    Jun 22, 2009
    Posts:
    39
    ah, crap... in all of my editing of the script, I must have messed that up. Thanks Andee, that did it.
     
  4. automata

    automata

    Joined:
    May 5, 2012
    Posts:
    1
    Texture offset is not the same thing as UV offset, which normally you need a reference to a Mesh instance to be able to alter. The difference may seem slight, but it's rather significant. I've heard that when you dynamically alter the texture offset of a material that is being used by more than one object, a copy of that material is made, which increases the number of materials used in the scene, thus the draw calls, and thus reduces performance. Editing the UVs of a mesh instance, however, does not copy the material, and is the better way to go if you're seeking optimization. So, is there a way do truly edit the UVs through a Mesh instance with LineRenderer?