Create prefab when somebody clicks.

Updated on March 21, 2018 in [A] GUI
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on March 20, 2018

I want to create a way to instantiate an object and set its position to the mouse position when its clicked. This would be done by clicking a button (runtime) to select a prefab and then once the button has been pressed, I want to check when the mouse has been clicked and spawn the object where it was clicked. The struggle I am having is to press the button, make it somehow give a visual feedback that it is selected, and spawning the object where the mouse was clicked IF the button was pressed. My game is 2.5d (3d but it has the concept of a 2d sidescroller). Please help me make this happen if you can!

  • Liked by
Reply
0 on March 21, 2018

Just make the button change colors until another button is pressed.

 

  • Liked by
Reply
Cancel
0 on March 21, 2018

You can change the color or the sprite of the button when you click it, and you should set a boolean in the script that holds the mouse click event, that will tell that script that you pressed the button. While this boolean is true, you will be checking for the MouseButtonDown event. When that happens, you set the boolean back to false, and with the mousePosition you can instantiate objects wherever u want

  • Liked by
Reply
Cancel