Afaik one issue here is that you are using x
the index of the touch. IsPointerOverGameObject
expects a fingerID as parameter!
The index x
of the touch you use for GetTouch
is NOT necessarily equal to the Touch.fingerId
!
It should rather be
if(!EventSystem.current.IsPointerOverGameObject(touch.fingerId))
Btw in general if you are going to iterate through all touches anyway it is easier to just use Input.touches
Returns list of objects representing status of all touches during last frame. (Read Only) (Allocates temporary variables).
var touches = Input.touches;
which allows you to filter touches out right away like e.g.
using System.Linq;
...
var touches = Input.touches;
var validTouches = touches.Where(touch => !EventSystem.current.IsPointerOverGameObject(touch.fingerId));
foreach(var touch in validTouches)
{
...
}
this is using Linq Where
and basically equals doing
var touches = Input.touches;
foreach(var touch in touchs)
{
if(!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) continue;
...
}
In general it still confuses me how/why it is supposed to use the same shared variables fp
and lp
for all possible touches.
You should probably rather use the
var moved = touch.deltaPosition;
And work with that value instead.
Or in general use only one of these touches by storing the first valid touch.fingerId
and later check if the touch is still of that id. Ignore all other touches meanwhile.
private int currentFingerId = int.MinValue;
...
// If you check that one first you can avoid a lot of unnecessary overhead ;)
if(!gameOver)
{
var touches = Input.touches;
var validTouches = touches.Where(touch => !EventSystem.current.IsPointerOverGameObject(touch.fingerId);
foreach (var touch in validTouches)
{
if(currentFingerId != int.MinValue && touch.fingerId != currentFingerId) continue;
switch(touch.phase)
{
case TouchPhase.Began:
currentFingerId = touch.fingerId;
break;
case TouchPhass.Moved:
// "touch.deltaPosition.x" is basically exactly what you calculated
// yourself using the "fp", "lp", "previous_rotate" and "movement"
var moved = touch.deltaPosition.x * 0.15f;
Platform_Control.transform.Rotate(0f, 0f, moved, Space.World);
break;
case TouchPhase.Ended:
currentFingerId = int.MinValue;
break;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…