Why first Input.touch doesn't work?

I used Input.touch million times until today, but this time I’m really baffled.

In the screen I’ve got a plane for background(a map), and some GameObjects called “Level” on it.

The function is very simple:
If I touch the “Level”, I open that level.
Instead, if I touch the map and drag it, I move it.
It’ similar to this: ScreenExample

The problem is:
If I touch the level with a finger, nothing happens.
But if I hold down on the screen one finger, the second finger that touch the level, it opens it.

It’s as if for some strange reason it jumps the input.touch[0]

This is my C# code:
MapStatus

I still do not understand why, and I’m sorry for my english :wink:

You are checking against every touch that is happening, all at once, therefore the second touch (Input.touch[1]) will call open level, bypassing the other touch functionality because the scene is changing.

If you only want one touch to have an effect, and any additional touches to not be registered, you will want to change your:

foreach (Touch touch in Input.touches)

and any touch references within that foreach loop to simply apply to:

Input.touches[0]

Also, your English is fine :slight_smile:

Total code block:

	if (Input.touches[0].phase == TouchPhase.Began) {
		Ray vRay = Camera.main.ScreenPointToRay(Input.touches[0]);
		RaycastHit vHit;
		if(Physics.Raycast(vRay, out vHit)){
			for(int i = 0; i < Levels.Count; i++){
				if(vHit.collider == Levels*.Target.collider){*
  •  		//Open level*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  • }*

I don’t see any problem with your code. Have you added some Debug.Logs what parts get executed, what position you get, if a collider is hit, if the collider is found in your list…?

I’m not sure what platform you develop for. If you’re on android you can use “adb logcat” to see the device log. If you’re testing on iPhone / iPad you should have a console in xcode.

Alternatively you can simply create a “mobile console” with a single GUI.label and a string variable. Something like this:

private static string m_LogText = "";
private Vector2 m_LogScrollPos;

public static void Log(string aText)
{
    m_LogText += aText + "

";
}

void OnGUI()
{
    GUILayout.BegineArea(new Rect(0,Screen.height*0.75f,Screen.width, Screen.height*0.25f))
    m_LogScrollPos = GUILayout.BeginScrollView(m_LogScrollPos);
    GUILayout.Label(m_LogText);
    if (GUILayout.Button("clear"))
        m_LogText = "";
    GUILayout.EndScrollView();
    GUILayout.EndArea();
}