Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    2,106
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    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:
    9,350
  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:
    2,106
    Use the SetPosition method.