Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Making Linerenderer change color after each point

Discussion in 'General Graphics' started by theboifgyapi, Jun 16, 2020.

  1. theboifgyapi

    theboifgyapi

    Joined:
    Jun 8, 2020
    Posts:
    2
    I am making a mobile game where you have to connect dots with a line. there are dots that are colored and do different things when you go on them, and I want to be able to make the line switch color whenever it goes on a new dot with a different color. I use the Line Renderer for drawing the lines, and I tried to use the gradient but that wasn't what I wanted since it always blended the colors no matter what I did to the gradient settings. There was also the problem of the 8 color limit, which is certainly not enough given that the most basic grid I use is 3x3 which is already over the limit. I tried using textures, but I'm not exactly sure how I could change the colors and width of the image during runtime to fit my needs. Any help is very much appreciated.
    in the imgur link you can see a representation I made with changing the texture by hand.
    https://imgur.com/a/PANY0Th
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,299
    One line renderer per connection?

    Depends how big your grids get.. might be bad for performance if you have 100’s of lines.
     
  3. theboifgyapi

    theboifgyapi

    Joined:
    Jun 8, 2020
    Posts:
    2
    Well I probabbly won't go 10x10 big, but I would like to keep it clean and easy to run on any device. I'm not too familiar with prefabs either so it might be a bit hard to deal with, since I'm pretty new to unity
     
  4. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,299
    I would hope that unity can cope with up to 100 line renderers without performance being awful, so I’d say give that a go :)

    Just make your “master” line renderer in the Hierarchy, drag it to the project view, and it’ll save a prefab. Then you can assign the prefab to a script, and instantiate it once per line that you need. Just set the appropriate color for each one instead of a complex gradient.

    Good luck!
     
    theboifgyapi likes this.