请将 Update
方法中的以下代码:
targetPos = touchPosition; //将屏幕坐标转换为世界坐标,作为目标位置
targetPos.z = 0;
if (currentCoroutine != null)
StopCoroutine(currentCoroutine);
currentCoroutine = StartCoroutine(MoveToTarget());
修改为:
if (IsTouchedOnPlayer(touch.position)) //如果触摸到角色,则返回,不进行移动操作
return;
else
{
targetPos = Camera.main.ScreenToWorldPoint(touch.position); //将屏幕坐标转换为世界坐标,作为目标位置
targetPos.z = 0;
if (currentCircle != null)
Destroy(currentCircle);
if (currentCoroutine != null)
StopCoroutine(currentCoroutine);
currentCoroutine = StartCoroutine(MoveToTarget());
}
这样就可以确保只有在触摸点不在角色上时才会触发移动操作。