- Home /
Question by
servet · Oct 12, 2012 at 06:36 PM ·
instantiateinputmousescreentoworldpoint
Object instantiates in the same spot (ScreenToWorldPoint)
Hi, I am trying to instantiate an object at the mouse x and y and a predefined z. This code instantiates the object at 0,1,-10 all the time, can anyone tell me the reason?
void Update () {
if(Input.GetMouseButtonDown(0)){
Debug.Log("mouse clicked");
Vector3 mousePos;
mousePos=Input.mousePosition;
mousePos.y=4;
mousePos.z=0;
Vector3 worldPos;
worldPos=Camera.main.ScreenToWorldPoint(mousePos);
Debug.Log(worldPos);
Instantiate(b,worldPos,Quaternion.identity);
}
Comment