protected virtual void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { CloseCurrentMenu(); } else if (Input.GetMouseButtonDown(1)) { CloseCurrentMenu(); var ray = RayCamera.ScreenPointToRay(Input.mousePosition); var hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo, maxDistance, layerMask)) { var menuAgent = hitInfo.transform.GetComponent <IContextMenuAgent>(); if (menuAgent != null) { CurrentMenu = FindContextMenu(menuAgent.MenuName); if (CurrentMenu != null) { CurrentMenu.Show(menuAgent, Input.mousePosition); } } } } }