{"id":31809,"date":"2024-11-01T09:03:09","date_gmt":"2024-11-01T09:03:09","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31809"},"modified":"2024-11-01T11:34:37","modified_gmt":"2024-11-01T11:34:37","slug":"unity-basics-course-shooting-1-shooting-with-bullets","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31809\/","title":{"rendered":"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets"},"content":{"rendered":"<p>Hello! In this course, we will create a simple shooting game using Unity. The main focus of our implementation will be on the &#8220;shooting bullets&#8221; feature. We will gradually learn the necessary functions and aim to complete a simple game at the end.<\/p>\n<h2>Table of Contents<\/h2>\n<ol>\n<li><a href=\"#section1\">Installing Unity and Basic Setup<\/a><\/li>\n<li><a href=\"#section2\">Creating a Project<\/a><\/li>\n<li><a href=\"#section3\">Setting Up a 2D Game Environment<\/a><\/li>\n<li><a href=\"#section4\">Creating a Bullet Prefab<\/a><\/li>\n<li><a href=\"#section5\">Writing the Character and Bullet Shooting Script<\/a><\/li>\n<li><a href=\"#section6\">Configuring and Testing Game Objects<\/a><\/li>\n<li><a href=\"#section7\">Conclusion<\/a><\/li>\n<\/ol>\n<h2 id=\"section1\">1. Installing Unity and Basic Setup<\/h2>\n<p>To install Unity, first download Unity Hub from the Unity website. After installing Unity Hub, install the desired version of the Unity Editor. Once the installation is complete, you can run Unity Hub to create a new project.<\/p>\n<h2 id=\"section2\">2. Creating a Project<\/h2>\n<p>In Unity Hub, click the <strong>New Project<\/strong> button and select the <strong>2D<\/strong> template. Name the project <strong>ShootingGame<\/strong> and set the save location, then click the <strong>Create<\/strong> button to create the project.<\/p>\n<h2 id=\"section3\">3. Setting Up a 2D Game Environment<\/h2>\n<p>Once the project is created, the Unity Editor will open. Here, we will place game objects and set up the camera and background.<\/p>\n<h3>3.1 Setting Up the Camera<\/h3>\n<p>Select the main camera and adjust the viewport to an appropriate size. In a 2D game, it&#8217;s common to set the camera&#8217;s <strong>Projection<\/strong> to <strong>Orthographic<\/strong>.<\/p>\n<h3>3.2 Adding a Background<\/h3>\n<p>Add an image to be used as the background in the Assets folder. Then drag it to the scene to place it. Set the z-axis value of the image lower than that of the camera to ensure the background is visible.<\/p>\n<h2 id=\"section4\">4. Creating a Bullet Prefab<\/h2>\n<p>We will create a simple sprite representing the bullet. Add the bullet sprite to the Assets folder and place it into the scene as a 2D object. After adjusting the size and properties of the bullet, drag this object into the <strong>Prefabs<\/strong> folder to save it as a prefab.<\/p>\n<h3>4.1 Setting Bullet Properties<\/h3>\n<p>Select the prefab and add a <strong>Rigidbody2D<\/strong> component. This component gives physical properties so that the bullet can move naturally. Set the <strong>Gravity Scale<\/strong> to 0 so that it is not affected by gravity.<\/p>\n<h3>4.2 Adding a Collider<\/h3>\n<p>Add a <strong>CircleCollider2D<\/strong> to the bullet prefab to set up the collider. This collider allows the bullet to detect collisions with other objects.<\/p>\n<h2 id=\"section5\">5. Writing the Character and Bullet Shooting Script<\/h2>\n<p>Now we need to write a script to control the shooting of the bullet. Let&#8217;s create the character and add the shooting functionality.<\/p>\n<h3>5.1 Creating the Character<\/h3>\n<p>Prepare a sprite to be used as the character and add it to the scene in the editor. Also, add a <strong>Rigidbody2D<\/strong> component to the character.<\/p>\n<h3>5.2 Writing the Script<\/h3>\n<p>Create the script for the character. Below is a basic C# script example to shoot bullets.<\/p>\n<pre><code>\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class PlayerController : MonoBehaviour\n{\n    public GameObject bulletPrefab; \/\/ Bullet prefab\n    public float bulletSpeed = 20f; \/\/ Bullet speed\n\n    void Update()\n    {\n        if (Input.GetKeyDown(KeyCode.Space)) \/\/ When the space bar is pressed\n        {\n            Shoot();\n        }\n    }\n\n    void Shoot()\n    {\n        GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity);\n        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();\n        rb.velocity = transform.up * bulletSpeed; \/\/ Set the bullet's speed in its direction\n    }\n}\n<\/code><\/pre>\n<h3>5.3 Connecting the Script<\/h3>\n<p>Add the written script to the character object and set the <strong>bulletPrefab<\/strong> variable to the bullet prefab in the inspector window.<\/p>\n<h2 id=\"section6\">6. Configuring and Testing Game Objects<\/h2>\n<p>All components are prepared, so let&#8217;s test if the game works well.<\/p>\n<h3>6.1 Running the Test<\/h3>\n<p>Click the play button to run the game. Check if the bullet is fired when the character presses the space bar. If needed, you can adjust the speed or direction to achieve the desired outcome.<\/p>\n<h3>6.2 Testing Bullet Collisions<\/h3>\n<p>It&#8217;s also important to add handling for when the bullet collides with other objects. For example, you could make the enemy disappear when hit by a bullet. To do this, write a script for the enemy object to check for collisions with the bullet.<\/p>\n<pre><code>\nusing UnityEngine;\n\npublic class Enemy : MonoBehaviour\n{\n    void OnTriggerEnter2D(Collider2D collision)\n    {\n        if (collision.gameObject.CompareTag(\"Bullet\"))\n        {\n            Destroy(gameObject); \/\/ Destroy the enemy object\n        }\n    }\n}\n<\/code><\/pre>\n<h2 id=\"section7\">Conclusion<\/h2>\n<p>In this course, we implemented a simple shooting mechanism using Unity. By learning the basic functions of shooting bullets and handling collisions, we have laid the groundwork for game development and a stepping stone for more advanced programming. I hope you continue to create various games with Unity!<\/p>\n<p>This concludes the Unity Basics Course &#8211; Shooting 1: A Shooting Tutorial Using Bullets. If you have any questions or comments, please leave them below. Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this course, we will create a simple shooting game using Unity. The main focus of our implementation will be on the &#8220;shooting bullets&#8221; feature. We will gradually learn the necessary functions and aim to complete a simple game at the end. Table of Contents Installing Unity and Basic Setup Creating a Project Setting &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31809\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets&#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-31809","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 Basics Course: Shooting 1 - Shooting with Bullets - \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\/31809\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: Shooting 1 - Shooting with Bullets - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this course, we will create a simple shooting game using Unity. The main focus of our implementation will be on the &#8220;shooting bullets&#8221; feature. We will gradually learn the necessary functions and aim to complete a simple game at the end. Table of Contents Installing Unity and Basic Setup Creating a Project Setting &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31809\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:03:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:34:37+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\/31809\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31809\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets\",\"datePublished\":\"2024-11-01T09:03:09+00:00\",\"dateModified\":\"2024-11-01T11:34:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31809\/\"},\"wordCount\":666,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31809\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31809\/\",\"name\":\"Unity Basics Course: Shooting 1 - Shooting with Bullets - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:03:09+00:00\",\"dateModified\":\"2024-11-01T11:34:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31809\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31809\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31809\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets\"}]},{\"@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 Basics Course: Shooting 1 - Shooting with Bullets - \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\/31809\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: Shooting 1 - Shooting with Bullets - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this course, we will create a simple shooting game using Unity. The main focus of our implementation will be on the &#8220;shooting bullets&#8221; feature. We will gradually learn the necessary functions and aim to complete a simple game at the end. Table of Contents Installing Unity and Basic Setup Creating a Project Setting &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets\"","og_url":"https:\/\/atmokpo.com\/w\/31809\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:03:09+00:00","article_modified_time":"2024-11-01T11:34:37+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\/31809\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31809\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets","datePublished":"2024-11-01T09:03:09+00:00","dateModified":"2024-11-01T11:34:37+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31809\/"},"wordCount":666,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31809\/","url":"https:\/\/atmokpo.com\/w\/31809\/","name":"Unity Basics Course: Shooting 1 - Shooting with Bullets - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:03:09+00:00","dateModified":"2024-11-01T11:34:37+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31809\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31809\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31809\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: Shooting 1 &#8211; Shooting with Bullets"}]},{"@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\/31809","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=31809"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31809\/revisions"}],"predecessor-version":[{"id":31810,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31809\/revisions\/31810"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}