How to check whether two or more different objects are being touched simultaneously by Touch Input

Hey guys,

I’m creating a game where a random number of tiles (1 - 3) are spawned and need to be touched simultaneously to progress.

I need help on how to determine whether all the tiles in the scene are being touched simultaneously.

Right now I have this script to deal with touch and there is a variable in another script that contains an integer value for the number of tiles spawned. I appreciate any help!

public class TouchController : MonoBehaviour {

    void Update () {

        for (var i = 0; i < Input.touchCount; ++i) {
           
            if (Input.GetTouch (i).phase == TouchPhase.Stationary || Input.GetTouch(i).phase == TouchPhase.Began) {
               
                Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (i).position);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit)) {
                    if (hit.transform.tag == "Tile") {
                        //if hit is tile do something                 
                   
                   
                   
                    }
                }
            }
        }
    }
}

You can create a list of TouchedTiles and as you touch a tile, add it to the list.

Before adding it, make sure to check if it’s already in the list, and then if not, simply add that Tile.

When the TouchedTiles list Count() matches the expected count, progress with the game.

Thanks, I’ll try that