Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Draw line between two objects without LineRenderer

Discussion in 'Scripting' started by CraftCreeperDev, Nov 10, 2018.

  1. CraftCreeperDev


    Sep 13, 2014
    I would like to recreate this using code, my first guess would be finding the angle, most likely trigonometry, difference in x and difference in y, and using cos to get the angle and use that as a base for the transformation to create a line. However, I cannot figure out a way to get the x and y coordinates of both ends of the rectangle.

    Also, I don't know how to determine wether it's above or below the horizontal. Read EDIT

    One final thing is that scale is not the same as length, i.e. just because something has a scale of 1 does not mean it has a length of 1 in terms of the distance between each end.

    This is an example of what I would like to replicate.

    Here is another:

    thanks for any help :D

    EDIT: After a bit of experimentation, I figured out that I can see if the difference in y is positive or negative and therefore determine if the line should be above or below the horizontal.