void OnGUI()
    {
        if (Event.current != null && Event.current.type == EventType.mouseDown)
        {
            if (Input.GetMouseButton(0))
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    GameObject selectedGmObj = hit.collider.gameObject; //获得点击的物体
                    if(selectedGmObj.name.Contains("Face"))
                    {
                        Debug.Log("Face");
                    }
                    else if (selectedGmObj.name.Contains("Hair"))
                    {
                        Debug.Log("Hair");
                    }
                    else if (selectedGmObj.name.Contains("Clothes"))
                    {
                        Debug.Log("Clothes");
                    }
                    else if (selectedGmObj.name.Contains("Accessory"))
                    {
                        Debug.Log("Accessory");
                    }
                }
            }
        }
    }

 

相关文章: