get touch down?

I have been making an iOS app and been using mousebuttondown for my raycasts which works fine. However if someone accidently has an extra finger on the screen it no longer works. Is it possible to handle multiple touches which a raycast easily?

Thanks

There must be an easy way to do this!

Can you post your code you are using for this? You might need to run your touch functions in a for loop but not 100% sure what you have.

Perhaps something like this?

for (var i : i in Input.touches) {
    if (i.phase == TouchPhase.Began) {
        raycast();
    }
}

I’m not at my home computer so no way to test, sorry.

	if (Input.GetMouseButtonDown(0))
    {
        //empty RaycastHit object which raycast puts the hit details into
        var hit : RaycastHit;
        //ray shooting out of the camera from where the mouse is
        var ray : Ray = cameraInterface.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, hit))

thanks for the suggestion, i will give it a go. I know I need to convert to unityscript but I will give it a go :slight_smile:

Im ten years later but try this

if (Input.touchCount > 0 && Input.GetMouseButtonDown(0))
{
    raycast();
}

but that wont work for multi touch

This should do the trick

if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
// Do something
}
2 Likes

this is perfect thanks !