Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta 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. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    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

Connect two waypoints in scene view using drag and drop

Discussion in 'Extensions & OnGUI' started by nicmarxp, Aug 7, 2018.

  1. nicmarxp


    Dec 3, 2017
    I’m making a waypoint system, where each node has one or more previous and next nodes which makes it possible for the paths to branch. Currently it’s a list of GameObjects, one for previous, and one for next nodes. This is manually set up and it would be really nice to be able to just connect them by dragging in the scene view.

    What I think I want to do first, is make an editor script, so when I select a node, a red (previous) and a green (next) handle is shown.

    The challenge here is to drag from one of the handles and see a visual red/green line connected to the mouse, and then I can release it on another node, and it will add the source nodes to the target list and the other way around. If I release it somewhere else, nothing happens.

    Should I use raycast (screenpointtoworld?) continuosly below the mouse and search for a node, and then somehow highlight it, to visualize that I can drop it?

    The nodes have rectangular colliders, which I guess helps with raycasting.

    I’d be happy for feedback before I start coding this, to see if it’s plausable. I haven’t found any other drag-drop-with-lines features so far, but it seems that it should work.

    Thanks! :)