I have set a orthographic size for my camera . And i take in touch position from the user ,
Like this.
RaycastHit2D hitInfo = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (touchPosition), Vector2.zero);
I can get other touch positions like this
Debug.Log (touchPosition);
This would give me the pixel value i guess . But i want to convert it to the range of 0,1 ,the zero at screen bottom and 1 at screen top.
so that i can later convert it into some position in grid layout cell . Here is the transformation i’m using for that
float maxX = Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellWidth / 2;
float minX = -(Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellWidth / 2);
float maxY = Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellHeight / 2;
float minY = -(Camera.main.gameObject.transform.GetComponent<gridadjustment> ().cellHeight / 2);
float scaleFactorX = touchPosition.x * (Math.Abs (maxX - minX))-minX;
float scaleFactorY = touchPosition..y * (Math.Abs (maxY - minY))- minY;
Here touch position is the value saved in this way( Camera.main.ScreenToWorldPoint (touchPosition))
and than i’m gonna use this scaleFactor to scale the game object locally inside the cell.
I can use this scaleFactorX and scaleFactorY if i had the touchPosition.x and touchPosition.y in the range of 0 to 1.