커서 잠금(Cursor.lockState 사용) 및 전체화면 모드(Screen.fullScreen 사용)는 모두 개별 HTML5 API(Element.requestPointerLock 및 Element.requestFullscreen)를 사용하여 구현되는 Unity WebGL에서 지원됩니다. Firefox 및 Chrome에서 지원되며, Safari에서는 현재 전체화면 및 커서 잠금을 사용할 수 없습니다.
브라우저에서는 보안과 관련한 이유로 마우스 클릭이나 키보드 누름과 같은 사용자가 시작한 이벤트에 직접 반응하기 위해서만 커서를 잠그거나 전체화면 모드로 전환할 수 있습니다. 아쉽게도 Unity는 분리 이벤트와 렌더링 루프를 지원하지 않기 때문에, Unity 스크립트에서 발생한 전체화면 모드나 커서 잠금 요청은 해당 요청을 발생시킨 이벤트에 대한 직접적인 반응으로 브라우저가 더 이상 인지하지 않을 때까지 이벤트를 지연시킵니다. 따라서 Unity는 커서 잠금이나 전체화면 요청을 발생시킨 이벤트 시점이 아니라, 다음 사용자가 시작한 이벤트 시점에서 요청을 발생시키게 됩니다.
이러한 제약에도 불구하고 올바른 결과를 얻으려면 커서 잠금이나 전체화면 요청을 마우스나 키보드 눌림 해제 이벤트가 아니라 눌림 이벤트에서 트리거해야 합니다. 이렇게 하면 해당 요청이 다음 사용자가 시작한 이벤트 시점까지 연기되더라도 사용자가 마우스나 키보드를 놓는 시점에서 요청을 트리거할 수 있게 됩니다.
Unity의 UI.Button 컴포넌트를 사용하면 OnPointerDown
메서드를 오버라이드하는 Button
의 서브클래스를 만들어 원하는 동작을 구현할 수 있습니다.
전체 화면 모드로 전환하거나 커서를 잠그기 전에 브라우저에서 알림 메시지를 표시하거나 사용자에게 허가를 요청할 수 있습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.