How can I spawn a game object/prefab on my mouse pointer while only hovering over a specific area?
I'm a total beginner in Unity and C#.
I'm creating a simple game in 2D with sprites. To be brief, I would like to spawn a game object or prefab with a left mouse click but only when the mouse pointer is hovering over a certain area in the scene. I then need the spawned object to be held and dragged along with the mouse pointer until the left mouse button is released.
I've created a script that let's me click on and drag an object around the scene but I would like to spawn the object first and then be able to keep holding the left mouse button and drag it to a new location and then release to drop the item into a new spot. Does this make sense?
Any suggestions on tutorials or videos I could take a look at?
I'm also not sure if I'm posting in the right place (total noob).
Thanks in advance.
Answer by tormentoarmagedoom · May 23, 2019 at 07:34 AM
Hello Donovan.
If you are new, and dont know where to start with this, i recommend you to read manuals / watch tutorials about this things and watch this tutorials:
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
https://www.youtube.com/watch?v=RGjojuhuk_s
https://www.youtube.com/watch?v=lmG8jhIZ7lA
After this, you should be able to know how to do what you want!
Good luck!
Your answer
![](https://koobas.hobune.stream/wayback/20220612201915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
prefab instatiating in a certain position, size and rotation? 0 Answers
Unity native 2d or Unity 2d toolkit? 0 Answers
[2D] Z-Ordering Shadows 0 Answers
2 running animations in a sprite sheet 0 Answers