What is the best way to get the program to wait until the user selects an object before continuing?

I am writing a program that has a map of node object and I am trying implement a button where the user creates a connection between two of these nodes. What I want it to do is after the button is pressed, it displays the prompt and then wait until the user selects and object, and this selected oject is then stored in a variable, node1. The user the selects the second object which is then stored in the variable node2. I started off having a variable called clickedNode which was set to the object being clicked on when the mouse clicked on the object and then made null when they released the mouse. I then tried a while loop which ran while the clickedNode was empty but unity didn’t like this because it was an infinite loop or something I think. I then tried messing around with coroutines and stuff but it would always just exit the coroutine even if the condition was false. Any ideas?

Make your interface controller a state machine, perhaps? Some problems become easier when you use a state machine, as each state can only do certain things.

You’ll have normal mode - waiting for drag/drop/click. Then you’ll have dragging modes, connecting modes and so on. The connect mode might have a message/icon displaying near the mouse pointer, or there could be a fixed spot on the screen where status and information shows up.

1 Like