Hi, I am just trying to spawn a little cube in my scene where I touch the screen. But the
behavior i get is the following:
As you can see it seems that whatever i get from ScreenToWorldPoint is centered around some sort of center (maybe the camera?) and also the input seems to be tiny (thats why i multiply the 2 touch inputs by 30 (i.e. touch.position.x*30) to be able to see the different cubes drawn on radically different places as I press different screen points (before the multiplication all of the cubes where drawn at the same spot more or less)
Seems like I am doing something wrong coordinate system wise, but i dont get what. Any help will be greatly appreciated, thanks!!!
function DebugCheckInput () {
while(true){
if(Input.touchCount >=1) {
touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began) {
//Camera.main.nearClipPlane
touchPos3D = Camera.main.ScreenToWorldPoint(Vector3(touch.position.x*30, touch.position.y*30, Camera.main.nearClipPlane));
Manager.use.SpawnDebugBlock (touchPos3D.x, touchPos3D.y);
}
else if (touch.phase == TouchPhase.Moved){
}
else if (touch.phase == TouchPhase.Ended)
{
}
}
yield;
}
}
function SpawnDebugBlock (xPosIn : float, yPosIn : float) {
// just to see where i am touching, if
var debug_cubes = gameObject.FindGameObjectsWithTag("Cube");
Instantiate (debug_cubes[0], Vector3(xPosIn, yPosIn, 0.0), Quaternion.identity);
}