检测同一物体中的两个对撞机

时间:2018-05-21 08:05:15

标签: c# object unity3d touch collider

我有一个问题,我有一个3D动画,我添加了两个碰撞器enter image description here

我这样做是因为我想检测用户何时触摸头部,胸部或腹肌区域。如图所示,在胸部上部区域,我还在臀部和头部添加了一个球体对撞机。我有碰撞器,我有这个脚本

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") { }    
    }
}

问题在于,当我统一运行鼠标时有时会检测到鼠标,有时候......当我构建并运行项目到我的手机时,总是检测到头部,但是没有检测到其他碰撞器。 怎么解决这个?

0 个答案:

没有答案