이 문제를 해결하는 방법이 필요합니다. 나는 그 문제가 무엇인지 알고 있으며, 나는 단지 실행 가능한 해결책이 필요하다.유니티 - 패널이 즉시 비활성화되고 다시 활성화됩니다 (C#)
그래서 기본적으로 MouseManager라는 스크립트가 있습니다.이 스크립트는 특정 게임 개체를보고있는지를 감지하고 "f"키를 누르면 UIManager라는 다른 스크립트에 GameObject의 패널을 엽니 다 (게임이 있습니다). 콘솔에서 f를 누를 수 있고 퍼즐이있는 UI를 사용할 수 있습니다).
기본적으로 사용자는 "f"또는 "esc"를 눌러 패널을 종료 할 수 있지만 "f"를 누르면 패널이 비활성화되지만 즉시 " 다시 여전히 게임 오브젝트보고, 두 검사 업데이트()
내가 누군가를 알고있는 경우이 문제가 내 신경을 점점로 의견을주십시오, 해결 방법을 필요로 : P
감사
편집 : 콘솔이란 콘솔처럼 보이는 GameObject가 있다는 뜻입니다.
EDIT 2 : 여기에 코드가 있습니다. 몇 가지 의견을 달아서 각각의 기능을 이해할 수 있도록하겠습니다. 이 난장판이기 때문에이 UIManager에 관해서는
void Start()
{
uiPuzzles = GameObject.Find("PuzzlesUI").GetComponentInChildren<UIManager>(); // Currently I have the UIManager set to a canvas called PuzzlesUI. I will soon be moving it to an empty GameObject.
}
void Update()
{
if (!uiPuzzles.invActive && !uiPuzzles.puzzleActive) // invActive and puzzleActive are two public booleans that just show if the inventory or any puzzle panel is empty (UIManager handles opening and closing the inventory too)
{
if (Input.GetButtonDown("Use") && !uiPuzzles.invActive && !uiPuzzles.puzzleActive) // Use key is bound to "f". Currently Im just checking if puzzleActive and invActive are still false.
{
ray = GetComponentInChildren<Camera>().ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 7)) // Raycast where you're looking
{
uiPuzzles.openPuzzleOverlay(hit.collider.name); // function in UIManager which will check if the hit collider is in a list of all the puzzle colliders currently added and if it is, open that panel.
}
}
}
}
... 곧 리팩토링됩니다
public void openPuzzleOverlay(string collider) // Get a panel name
{
foreach (Puzzle item in puzzleList)
{
item.panelGameObject.SetActive(false); // Disable all puzzle panels.
if (item.consoleGameObject.name == collider) // unless its the given panel,
{
item.panelGameObject.SetActive(true); // then enable it.
Cursor.lockState = CursorLockMode.None; // Unlock the mouse.
Cursor.visible = true; // Show the mouse.
DisablePlayerUI(); // Disable the UI (e.g. crosshair)
puzzleActive = true; // Disable movement. (Because player movement requires puzzleActive and invActive to also be false
}
}
}
void Update()
{
if (Input.GetButtonDown("Use") && puzzleActive && !invActive && // If you want to use a console and the puzzle is already active
!puzzleList.Where(p => p.panelGameObject.activeSelf).FirstOrDefault().panelGameObject.GetComponentInChildren<InputField>().isFocused) // Check if the currently active panel's input field is not focused.
{
ClosePuzzleOverlay(); // Close the puzzle.
EnablePlayerUI(); // Enable the UI.
}
}
public void ClosePuzzleOverlay()
{
foreach (Puzzle item in puzzleList)
item.panelGameObject.SetActive(false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
puzzleActive = false;
}
코드 –
완료를 게시하십시오. 미안 그것은 너무 오래 걸렸고, 약간의 설명 주석을 추가해야했다. –