- Home /
Duplicate Question
how can you make an instantiated game object appear in the position where the mouse was clicked?
var shine : GameObject; var clone : GameObject; //var position : Vector3; function Start () {
}
function Update () {
//if(postion: Vector3(0,0,0))
if(Input.GetMouseButtonDown(0))
{
Debug.Log("Pressed left click.");
Instantiate (shine, Input.mousePosition,Quaternion.identity);
//Invoke ("Spawn", Random.Range( 0, 1));
Destroy(GameObject.Find("Shine(Clone)"), 3);
}
if(Input.GetMouseButtonDown(1))
{
Debug.Log("Pressed right click.");
}
if(Input.GetMouseButtonDown(2))
{
Debug.Log("Pressed middle click.");
}
}
There are many answer to this question on UA. And there are several ways to find the mouse position in world space depending your situation. Here are three answer I found Googling with your title.
http://answers.unity3d.com/questions/381636/how-to-instantiate-object-on-mouse-click-at-mouse.html
http://answers.unity3d.com/questions/485622/instantiate-on-mouse-position.html
http://answers.unity3d.com/questions/391337/how-to-place-a-prefab-in-the-current-mouse-positio.html
Follow this Question
Related Questions
Can't get Instantiated Object to Follow Mouse Position(Solved) 2 Answers
mouse position on tag 1 Answer
Checking if object intersects? 1 Answer
instantiate object at mouse position 4 Answers
Unity mouse input gradually becomes off 0 Answers