Make a game object appears at mouse position when clicked

Hi all :)

I'm new to scripting and i'm wonder how can i make a gameobject appears at the moust position when i left-click on the screen. Can you give me some hints?


You can use raycast from mouse position. see this example.

Thanks for your answers :)

I have take a look at the document and have nearly archived what i want. When I left-click on the screen, the game objects does appear but they all appear at the same place, not at my mouse position. My game is in 2D plane, so i only want to use X and Y axis.

Btw, how can i add my code to my answer??

If you want the object appears in hit point you should use RaycastHit.point instead of transform.position. You can find examples of RaycastHit here .

Yeah i have the same problem plz help