{"id":32073,"date":"2024-11-01T09:05:27","date_gmt":"2024-11-01T09:05:27","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32073"},"modified":"2024-11-01T11:33:25","modified_gmt":"2024-11-01T11:33:25","slug":"unity-basic-course-hide-mouse-cursor","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32073\/","title":{"rendered":"unity basic course: hide mouse cursor"},"content":{"rendered":"<p><body><\/p>\n<p>In this tutorial, we will learn how to hide and control the mouse cursor in Unity. Hiding and controlling the mouse cursor during the development of games or simulations is an important technique that helps enhance user experience. This is particularly essential when managing interactions in FPS (first-person shooter) games or with specific UI elements.<\/p>\n<h2>1. Overview<\/h2>\n<p>Hiding the mouse cursor is a straightforward process in Unity. This can increase the user&#8217;s immersion, allowing them to focus more on specific elements on the screen. To hide the cursor and implement certain functionalities, some basic script modifications and UI settings are required.<\/p>\n<h3>1.1. What to Expect?<\/h3>\n<p>Through this tutorial, we aim to achieve the following goals:<\/p>\n<ul>\n<li>Understanding how to hide the mouse cursor in Unity<\/li>\n<li>Managing mouse state with event triggers<\/li>\n<li>Creating a user interface for cursor control<\/li>\n<li>Adding advanced features using scripts<\/li>\n<\/ul>\n<h2>2. Setting Up Unity Environment<\/h2>\n<p>First, we need to set up a Unity project. This will proceed under the assumption that Unity is already installed.<\/p>\n<h3>2.1. Creating a New Project<\/h3>\n<p>Open Unity Hub and click the &#8216;New Project&#8217; button. Here are the basic settings:<\/p>\n<ul>\n<li>Project Name: <code>MouseCursorHiding<\/code><\/li>\n<li>Template Selection: <code>3D<\/code><\/li>\n<li>Location: Set your desired location.<\/li>\n<\/ul>\n<p>Then click the &#8216;Create&#8217; button to generate the project.<\/p>\n<h3>2.2. Setting Up the Initial Scene<\/h3>\n<p>To set up the scene, we will add a simple 3D object. For example, add a cube or a plane.<\/p>\n<ul>\n<li>In the Hierarchy window, select <code>Right Click<\/code> &gt; <code>3D Object<\/code> &gt; <code>Cube<\/code> to add a cube.<\/li>\n<li>Adjust the size of the cube to a suitable dimension and position it at the center.<\/li>\n<\/ul>\n<h2>3. Writing the Basic Script<\/h2>\n<p>We need to write a script to hide the mouse cursor. We will use C# for this.<\/p>\n<h3>3.1. Creating the Script<\/h3>\n<p>The next step is to create a new C# script.<\/p>\n<ul>\n<li>In the Project window, select <code>Right Click<\/code> &gt; <code>Create<\/code> &gt; <code>C# Script<\/code> to create a new script.<\/li>\n<li>Name the script <code>CursorController<\/code>.<\/li>\n<li>Double-click on the newly created script to open it in a code editor.<\/li>\n<\/ul>\n<h3>3.2. Writing the Code<\/h3>\n<p>The code to write is as follows:<\/p>\n<pre><code>using UnityEngine;\n\npublic class CursorController : MonoBehaviour\n{\n    void Start()\n    {\n        \/\/ Hide the cursor.\n        Cursor.visible = false;\n        \/\/ Set the cursor lock state to center.\n        Cursor.lockState = CursorLockMode.Locked;\n    }\n\n    void Update()\n    {\n        \/\/ Change the cursor state when the mouse button is clicked.\n        if (Input.GetMouseButtonDown(0))\n        {\n            ToggleCursor();\n        }\n    }\n\n    void ToggleCursor()\n    {\n        \/\/ Show or hide based on the current cursor state.\n        if (Cursor.visible)\n        {\n            Cursor.visible = false;\n            Cursor.lockState = CursorLockMode.Locked;\n        }\n        else\n        {\n            Cursor.visible = true;\n            Cursor.lockState = CursorLockMode.None;\n        }\n    }\n}\n<\/code><\/pre>\n<p>The above script hides the cursor and locks it in place when the game starts. When the user clicks the mouse button, it toggles the visibility of the cursor.<\/p>\n<h2>4. Applying the Script<\/h2>\n<p>You need to apply the written script to the scene.<\/p>\n<ul>\n<li>Select <code>Cube<\/code> from the Hierarchy.<\/li>\n<li>In the Inspector window, click the <code>Add Component<\/code> button and search for <code>CursorController<\/code> to add it.<\/li>\n<\/ul>\n<p>Now, when you run the scene, you will see that the mouse cursor is hidden. Clicking the mouse button will make the cursor reappear.<\/p>\n<h2>5. Adding Advanced Features<\/h2>\n<p>After implementing the basic cursor hiding functionality, you can develop additional advanced features.<\/p>\n<h3>5.1. Integration with UI Elements<\/h3>\n<p>When interacting with the in-game UI, there may be a need to show the cursor. You can make it so the cursor appears when clicking on the UI.<\/p>\n<p>To do this, add UI click detection to the <code>ToggleCursor<\/code> method:<\/p>\n<pre><code>using UnityEngine;\nusing UnityEngine.EventSystems;\n\npublic class CursorController : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler\n{\n    void Start()\n    {\n        Cursor.visible = false;\n        Cursor.lockState = CursorLockMode.Locked;\n    }\n\n    void Update()\n    {\n        if (Input.GetMouseButtonDown(0))\n        {\n            ToggleCursor();\n        }\n    }\n\n    void ToggleCursor()\n    {\n        if (Cursor.visible)\n        {\n            Cursor.visible = false;\n            Cursor.lockState = CursorLockMode.Locked;\n        }\n        else\n        {\n            Cursor.visible = true;\n            Cursor.lockState = CursorLockMode.None;\n        }\n    }\n\n    public void OnPointerEnter(PointerEventData eventData)\n    {\n        Cursor.visible = true;\n    }\n\n    public void OnPointerExit(PointerEventData eventData)\n    {\n        Cursor.visible = false;\n        Cursor.lockState = CursorLockMode.Locked;\n    }\n}\n<\/code><\/pre>\n<p>This will enable the cursor to be visible when hovering over UI elements and hide again when it leaves the UI.<\/p>\n<h2>6. Conclusion and Final Testing<\/h2>\n<p>Once all the above steps are completed, it\u2019s time to build the project and conduct testing. Make sure all functions work correctly and make adjustments as needed.<\/p>\n<h3>6.1. Build Settings<\/h3>\n<ul>\n<li>In the top menu, click <code>File<\/code> &gt; <code>Build Settings<\/code>.<\/li>\n<li>Select the platform and click the <code>Switch Platform<\/code> button.<\/li>\n<li>Add the necessary scenes and click the <code>Build<\/code> button to create the executable file.<\/li>\n<\/ul>\n<h3>6.2. Final Result Check<\/h3>\n<p>Run the generated executable to check if the mouse cursor hides properly, and confirm that it interacts correctly with other UI elements.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we learned how to hide the mouse cursor in Unity. We implemented various features, from writing basic scripts to integrating with UI elements. These skills are highly useful in the development of various games and applications, so make sure to utilize them fully.<\/p>\n<p>I hope you continue to gain more professional skills through various Unity-related tutorials. Thank you!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will learn how to hide and control the mouse cursor in Unity. Hiding and controlling the mouse cursor during the development of games or simulations is an important technique that helps enhance user experience. This is particularly essential when managing interactions in FPS (first-person shooter) games or with specific UI elements. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32073\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;unity basic course: hide mouse cursor&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[135],"tags":[],"class_list":["post-32073","post","type-post","status-publish","format-standard","hentry","category-unity-basic"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32073\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we will learn how to hide and control the mouse cursor in Unity. Hiding and controlling the mouse cursor during the development of games or simulations is an important technique that helps enhance user experience. This is particularly essential when managing interactions in FPS (first-person shooter) games or with specific UI elements. &hellip; \ub354 \ubcf4\uae30 &quot;unity basic course: hide mouse cursor&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32073\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:05:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:25+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"unity basic course: hide mouse cursor\",\"datePublished\":\"2024-11-01T09:05:27+00:00\",\"dateModified\":\"2024-11-01T11:33:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/\"},\"wordCount\":640,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32073\/\",\"name\":\"unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:05:27+00:00\",\"dateModified\":\"2024-11-01T11:33:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32073\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32073\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"unity basic course: hide mouse cursor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32073\/","og_locale":"ko_KR","og_type":"article","og_title":"unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this tutorial, we will learn how to hide and control the mouse cursor in Unity. Hiding and controlling the mouse cursor during the development of games or simulations is an important technique that helps enhance user experience. This is particularly essential when managing interactions in FPS (first-person shooter) games or with specific UI elements. &hellip; \ub354 \ubcf4\uae30 \"unity basic course: hide mouse cursor\"","og_url":"https:\/\/atmokpo.com\/w\/32073\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:05:27+00:00","article_modified_time":"2024-11-01T11:33:25+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32073\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32073\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"unity basic course: hide mouse cursor","datePublished":"2024-11-01T09:05:27+00:00","dateModified":"2024-11-01T11:33:25+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32073\/"},"wordCount":640,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32073\/","url":"https:\/\/atmokpo.com\/w\/32073\/","name":"unity basic course: hide mouse cursor - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:05:27+00:00","dateModified":"2024-11-01T11:33:25+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32073\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32073\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32073\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"unity basic course: hide mouse cursor"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32073"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32073\/revisions"}],"predecessor-version":[{"id":32074,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32073\/revisions\/32074"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}