我这样做是因为我想检测用户何时触摸头部、胸部或腹肌区域。如图所示,在胸部上部区域,我在臀部和头部添加了一个球体对撞机。我有对撞机,我有这个脚本
public class OnTouch : MonoBehaviour
{
public int cuerpo = 2;
void Update ()
{
if (!Input.GetMouseButtonDown(0)) return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.Log("entre");
if (!Physics.Raycast(ray,out hit)) return;
Debug.Log("entre2");
Debug.Log(hit.collider.name);
if (hit.collider.name == "head") { }
else if (hit.collider.name == "chestUpper") { }
else if (hit.collider.name == "abdomenUpper") { }
else if (hit.collider.name == "hip") { }
}
}
问题是,有时我在统一运行时检测到鼠标,有时..当我构建项目并将其运行到我的手机时,总是检测到头部,但没有检测到其他碰撞器。如何解决这个问题?