Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dashed Line in unity

Discussion in 'Scripting' started by TalhaJawed, Apr 2, 2020.

  1. TalhaJawed

    TalhaJawed

    Joined:
    Sep 18, 2019
    Posts:
    10
    I want to draw dashed line between two game objects. Can someone tell me how linerender can be utilized to draw dashed(dotted) line between two objects??
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    You could probably use a texture with a dashed line, then either use LineRenderer or just a quad with a texture if you have a straight line.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    You can also use a series of line renders, one renderer per dash. Alternately there is this asset:

    https://assetstore.unity.com/packages/tools/particles-effects/vectrosity-82

    Or you can make your own geometry. Depends really on what is easiest for you. I have a sample geometry-making project here called MakeGeo, but it does NOT have this exact use case example in it.

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
    Bunny83 likes this.
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    You'll need one section of your dotted line texture containing one line and one gap.
    Make a material and apply the texture. I recommend Legacy>Transparent>Diffuse for simplicity sake.
    Apply the material to the line renderer
    Adjust the tiling in the material to your liking.
     
  5. Solocov

    Solocov

    Joined:
    Apr 16, 2016
    Posts:
    3
    mopthrow likes this.
  6. unity_31130666

    unity_31130666

    Joined:
    Jan 10, 2020
    Posts:
    8
    Add this material to your LineRenderer
     

    Attached Files:

  7. ghoooreee

    ghoooreee

    Joined:
    Sep 8, 2021
    Posts:
    1
    thanks man! it worked great
     
    nour-s likes this.
  8. nour-s

    nour-s

    Joined:
    May 30, 2017
    Posts:
    4
    You have no idea how many google searches, StackOverflow questions, Reddit posts, and Unity forums posts I have to read just to find your magic solution.

    Thank you.
     
  9. asturgis

    asturgis

    Joined:
    Apr 6, 2020
    Posts:
    1
    thank you, you saved me so much time!
     
  10. Markstam291

    Markstam291

    Joined:
    Mar 23, 2015
    Posts:
    12
    Thanks so much, you save my life.
     
    xucian likes this.