Search Unity

Line Renderer Stretching and compressing weirdly

Discussion in 'General Graphics' started by ryanlin138, Aug 28, 2019.

  1. ryanlin138

    ryanlin138

    Joined:
    Aug 28, 2019
    Posts:
    6
    connection.PNG

    I have a script that controls the positions of the line renderer. I want it to display this conveyor belt texture (below). It seems to tile the last row of the texture instead of tiling the whole thing.
    stretching.PNG

    I set up the material like this (below).
    material.png

    Am I doing something wrong? It would just either stretch the texture or tile the texture weirdly if I change the texture mode.
    Code (CSharp):
    1.  
    2.     Vector3[] GenerateConnection() //Generate a connection for two gameObjects. This method rests on a "Connection" class.
    3.     {
    4.         startPos = start.position;
    5.         endPos = end.position;
    6.  
    7.         Vector3[] connection = new Vector3[4]; // connection stores the Vector3s that are in the line.
    8.         connection[0] = startPos; //starting position of the "connection"
    9.         connection[3] = endPos; //ending position of the "connection"
    10.         connection[1] = new Vector3(Mathf.Lerp(startPos.x, endPos.x, 0.5f), startPos.y, Mathf.Lerp(startPos.z, endPos.z, 0.5f));
    11.         connection[2] = new Vector3(Mathf.Lerp(startPos.x, endPos.x, 0.5f), endPos.y, Mathf.Lerp(startPos.z, endPos.z, 0.5f));
    12.  
    13.         line.SetPositions(connection);
    14.  
    15.         line.material.SetTextureScale("_MainTex", new Vector2(DistanceVector3Array(connection), 1));
    16.  
    17.         return connection;
    18.     }
    19.  
    20.  
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Texture "wrap mode" set to "repeat"?
     
    richardkettlewell likes this.
  3. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    As @mouurusai suggests, probably the problem is in the texture importer settings for that texture, rather than the line renderer settings. Check the wrap mode :)
     
    pojay11523 and KarlKarl2000 like this.