Search Unity

How to create a visible raycast between two objects?

Discussion in 'Physics' started by CraftingStudio12, Sep 2, 2019.

  1. CraftingStudio12

    CraftingStudio12

    Joined:
    Oct 22, 2016
    Posts:
    14
    I've seen tutorials on raycasting but how would I be able to create a visual line between the two objects instead?
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    784
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    1,972
    You didn't state if it were for in-game rendering feature or simply for debugging purposes. For debugging you can use Debug.DrawLine.
     
  4. CraftingStudio12

    CraftingStudio12

    Joined:
    Oct 22, 2016
    Posts:
    14
    Sorry, forgot to mention,it's for in-game purposes and for 3D rendering
     
    MelvMay likes this.
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,435
  6. CraftingStudio12

    CraftingStudio12

    Joined:
    Oct 22, 2016
    Posts:
    14
  7. CraftingStudio12

    CraftingStudio12

    Joined:
    Oct 22, 2016
    Posts:
    14
    I want the line to be generated through code because the objects will be instantiated too, how can I alter the positions of the start and endpoints in code?


    Vector3 b = new Vector3(0, 0, 0);
    GameObject Line = Instantiate(linez, b, transform.rotation);
    Line.Positions.element 0?
     
  8. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    784
    Use the SetPosition method.