I am trying to locate a cube object at the position where I touched with this code.
However, the only result I can see is "Touched". I think ScreenToWorldPoint is not working. Did I made a mistake in this code?
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0)
{
UnityEngine.Debug.Log("Touched");
Vector2 pos_2 = Input.GetTouch(0).position;
Camera camera = GetComponent();
Vector3 pos_3 = camera.ScreenToWorldPoint(pos_2);
UnityEngine.Debug.Log("pos_3: "+pos_3);
//Vector3 pos_3 = new Vector3(pos_2.x, pos_2.y, 0);
transform.position = pos_3;
}
}
}
↧