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]
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
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){*
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: