- Home /
Question by
Junglee · Jul 23, 2014 at 01:48 PM ·
javascriptmonodevelop
Placing 3d model onmouseclick
Hi,
I am trying to place a 3d model onmouseclick event. Right now i am able to get position on the terrain using raycast, so 'll have the coordinate where i want to place the object but the problem is how to create an object and place it on that coordinates.
please suggest me tips/tricks for that.
code to detect coordinates on terrain:
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit1))
{
transform.position = hit1.point;
}
}
}
i have searched on net regarding this and i found instantiating the object, but i think this is not exactly what i am looking for, here's the code:
Instantiate(Object, hit1.point, Quaternion.identity);
UPDATE:
I have found this useful link which places model on mouseclick.
SEE HERE for mouseplacement script.
and suggest how can i place 3d models like Tank, weapons etc....
Comment
Have you tried to put your model prefab to that "ObjectToPlace" public var