- Home /
trying to get an object to follow mouse on GUI click
what i am trying to do is have a prefab follow my mouse when i click a GUI button then when i click again i want the object to stay there. im having trouble getting the object to move after i instantiate it. how would i make the object follow my mouse after instantiating? is there a way to do this using the DragRigidbody in the Standard Assets?
Answer by AngryOldMan · Mar 31, 2011 at 02:49 AM
I think what you want is info on click to move and then just basic knowledge of boolean functions and the GUI function to use 2D on screen buttons to turn sections of script "on and off"
i know how to do that but i dont know what variable in the dragrigidbody script to transform my prefab to
i never said dragrigidbody. look up click to move on unity answers and on google, many answers to do with diablo style click games, wow style click game etc they all ask the same thing as do you.
I think you misunderstood me. What i want is when i click my GUI button, i want an object to be instantianted then at the same moment, move to my mouse. After i click, the object should follow my mouse around until i click again (releasing the object).
I understand more clearly now. you still want the exact same thing but rather than click to move you want to click to turn on a boolean allowing part of the click to move script to start working (needs to be in function Update), think it may involve raycasting too, which would return your mouse's 2D screen postion to a location in your 3d environment.learn about using basic GUI's as that is the easiest part to this. Then learn how to script your particular move system, once you have some code post it here if you have problems, no one will just write you this code though.