Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    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. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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.