I have an app that spawns a model on user click, and when the user taps the model, a menu pops up.
(我有一个可以在用户单击时生成模型的应用程序,当用户点击模型时,会弹出一个菜单。)
When the user taps anywhere else except the canvas element, the menu closes.
(当用户轻按画布元素以外的其他任何位置时,菜单都会关闭。)
But this is not working, when I press the canvas element, it detects the canvas element, but still, the menu closes.
(但这是行不通的,当我按下canvas元素时,它检测到canvas元素,但菜单仍然关闭。)
Here is my code:
(这是我的代码:)
void Update()
{
UpdatePlacementPose();
UpdatePlacementIndicator();
if (Input.touchCount > 0 )//&& Input.GetTouch(0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit;
debugText.text = "touched";
// Check if finger is over a UI element
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
Debug.Log("Touched the UI");
debugText1.text = "Touched the UI";
isui = true;
}
else
{
isui = false;
if (Physics.Raycast(ray, out hit) && (hit.transform.name != "Quad"))
{
//debugText.text = hit.transform.name;
debugText.text = Input.touchCount.ToString();
if (IsSpawned)
{
debugText1.text = ColourImage.activeSelf.ToString();
ColourImage.SetActive(true);
//debugText.text = objectToPlace.name;
}
}
else
{
if (placementPoseIsValid && Input.touchCount > 0 && !IsSpawned)
{
PlaceObject();
IsSpawned = true;
PlayerPrefs.SetString("type", "medium");
}
else
{
ColourImage.SetActive(false);
}
}
}
}
//if (placementPoseIsValid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
//{
// PlaceObject();
//}
}
ask by Jerin Cherian translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…