instantiating object at mouse position

hi everyone! i have a little problem… i have a 3d game and i want to create a object at mouse position in the 3d space… to make a game like the sims but when i try the code, when i click it spawns the object in another place… i dont know what is hapening

using UnityEngine;


2.using System.Collections;


3.


4.public class PlankCreator : MonoBehaviour {


5.


6.    public GameObject particle;


7.    void Update()


8.    {


9.        if (Input.GetButtonDown("Fire1"))


10.        {


11.            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);


12.            if (Physics.Raycast(ray))


13.                Instantiate(particle, Input.mousePosition, transform.rotation);


14.        }


15.    }}


16.

You want to Instantiate the object at the position the ray collides, not the position your mouse is on the screen.

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
    Instantiate(particle, hit.point, transform.rotation);
}

there is a problem… my object is spawning in the middle of the object no matter where i click