Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Draw line between two objects without LineRenderer

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

  1. CraftCreeperDev

    CraftCreeperDev

    Joined:
    Sep 13, 2014
    Posts:
    247
    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.
    (https://imgur.com/a/kKDVRV4)

    Here is another:
    https://imgur.com/a/NiK9LmA

    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.