I’ve tried the following codes but it doesn’t seem to work on my android device and on ios simulator.
function Update(){
if(Input.touchCount > 0){
if(Input.GetTouch(0).phase == TouchPhase.Began){
var x = checkTouch(Input.GetTouch(0).position);
}
}
}
function checkTouch(pos){
var wp : Vector3 = Camera.main.ScreenToWorldPoint(pos);
var touchPos : Vector2 = new Vector2(wp.x, wp.y);
var hit = Physics2D.OverlapPoint(touchPos);
if(hit){
//destroy my object
//return something
}
}
Touch is detected but something seems to be wrong with the function checkTouch() line1 - line 3. However, when i am using the code in update() function:
if(Input.GetMouseButtonDown(0)) {
var x = checkTouch(Input.mousePosition);
}
The checkTouch() function works nicely, the object is destroyed.
Anyone can help or provide me with a solution?
Thanks in advance.