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 Mesh Renderer/Shader Stretching Material (not tiling) !!!

Discussion in '2D' started by ipetepete, Apr 6, 2015.

  1. ipetepete

    ipetepete

    Joined:
    Feb 12, 2015
    Posts:
    2
    Sorry if this isn't the right place to post.

    I need help figuring out how to fix this. I've got a mesh renderer with a shader and the material is being stretched instead of being tiled. I should mention this was working fine before Unity 5

    Here is a screen pic of the issue (the bottom texture, the floor is being stretched)...


    Here is what the material looks like (unstretched)....




    Here is the code that makes the material scroll:

    Code (CSharp):
    1. void Update ()
    2.     {
    3.         if (!paused)
    4.         {
    5.             offset = mainRenderer.material.mainTextureOffset;
    6.             offset.x += startingSpeed * speedMultiplier * Time.deltaTime;
    7.  
    8.             if (offset.x > 1)
    9.                 offset.x -= 1;
    10.  
    11.             mainRenderer.material.mainTextureOffset = offset;
    12.         }
    13.     }
    Any help would be greatly appreciated. I've been banging my head over this one and can't find a fix.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    I guess you have checked that Wrap Mode is set to Repeat?
     
    ipetepete likes this.
  3. ipetepete

    ipetepete

    Joined:
    Feb 12, 2015
    Posts:
    2
    Thanks PGJ!

    Setting wrap mode did the trick.
    Code (CSharp):
    1. mainRenderer.material.mainTexture.wrapMode = TextureWrapMode.Repeat;
    2.  
    But only half of it, the texture was still stretching half the length of the mesh, so I had to delete the material and create a new one, which fixed the stretching.