instantiate an object from touch position
Vector3 touchDeltaPosition = Input.GetTouch(0).position; Instantiate(bulletPrefab, touchDeltaPosition, Quaternion.identity);
I wrote this code trying to instantiate the object from the touch position which is not working I think I'm doing it wrong can someone help me reach my goal to instantiate the object where I touch on screen and it's inside Update() method
the touch position is in screenspace, 2D, which has no idea of where it is in a 3D spatial environment, but the camera does. change the z value of position to something larger than 0 and use Camera.main.ScreenToWorldPoint(). the result is at distance you defined for z in front of the camera
omg thank you so much sir !! you solved my problem I really appreciate your answer.
Your answer
Follow this Question
Related Questions
Getting an object's y coordinate 2 Answers
gameobject.transform.position not working correctly 3 Answers
Getting position of a coordinate on the surface of a sphere 0 Answers
entire project lost touch input 0 Answers
Get colour of a pixel on a texture? 2 Answers