- Home /
Instantiate Prefab
worldPos = Camera.main.ScreenToWorldPoint(touch.position);
worldPos.z=0;
Instantiate(cut,worldPos,Quaternion.Euler(0,0,Random.Range(80,100)));
What did I do wrong? When i touch the screen the Prefab only appears in the middle of the screen.
Answer by LK84 · Jan 09, 2017 at 04:21 PM
Touch.position is a Vector2. The implicit conversion from Vector2 to Vector3 ( see here), since ScreenToWorldPoint expects a Vector3 as a parameter, leads to the following statement:
worldPos = Camera.main.ScreenToWorldPoint(touch.position.x, touch.position.y,0);
you set the near clipping plane distance to zero. This basically means you projected the scene into one single point. Use something like this instead:
worldPos = Camera.main.ScreenToWorldPoint(touch.position.x, touch.position.y,Camera.main.nearClipPlane);
Hello thanks for your fast answer. It worked and really helped me .
Your answer
Follow this Question
Related Questions
Problem with ScreenToWorldPoint and touches (C#) 2 Answers
Continually Updating position of Instantiated Object (to Mouse Pointer) 0 Answers
Object instantiates in the same spot (ScreenToWorldPoint) 0 Answers
Instantiate Game object at clicked position? 3 Answers
[Not Solved]Instintiated gameobject(sprite) wont load on scene 1 Answer