{"id":31797,"date":"2024-11-01T09:03:01","date_gmt":"2024-11-01T09:03:01","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31797"},"modified":"2024-11-01T11:34:40","modified_gmt":"2024-11-01T11:34:40","slug":"unity-basics-course-implementing-invisible-shooting","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31797\/","title":{"rendered":"Unity Basics Course: Implementing Invisible Shooting"},"content":{"rendered":"<p><body><\/p>\n<p>In this course, we will learn how to implement &#8216;invisible shooting&#8217; using the Unity engine. This course is for those who have a basic understanding of Unity, and it will help if you know the basics of scripting and how to use game objects.<\/p>\n<h2>1. Setting Up the Project<\/h2>\n<p>First, create a new Unity project. Open the Unity Hub, click the &#8216;New&#8217; button, and select the &#8216;3D&#8217; project template. Set the project name to &#8216;InvisibleShooting&#8217;, choose a suitable save location, and then click the &#8216;Create&#8217; button.<\/p>\n<h2>2. Structuring the Scene<\/h2>\n<p>Now let&#8217;s structure the basic scene. Create an empty game object and name it &#8216;Game Manager&#8217;, then create game objects named &#8216;Player&#8217; and &#8216;Enemy&#8217; underneath it.<\/p>\n<h3>2.1 Creating the Player<\/h3>\n<p>Select the &#8216;Player&#8217; object, then choose 3D Object > Cube to create a cube. Adjust the size of the cube to be used as the player character. Then, add a Rigidbody component to give it physical properties.<\/p>\n<h3>2.2 Creating the Enemy<\/h3>\n<p>Create the &#8216;Enemy&#8217; object in the same way with a cube. This object should also have a Rigidbody component added, and the enemy&#8217;s size and position should be set at a certain distance from the player.<\/p>\n<h2>3. Scripting<\/h2>\n<p>To make the sprite invisible, we need to set the opacity to 0. Let&#8217;s implement this in the script.<\/p>\n<h3>3.1 Creating the PlayerController Script<\/h3>\n<pre>\n<code>using UnityEngine;\n\npublic class PlayerController : MonoBehaviour\n{\n    public float moveSpeed = 5f;\n\n    void Update()\n    {\n        float moveHorizontal = Input.GetAxis(\"Horizontal\");\n        float moveVertical = Input.GetAxis(\"Vertical\");\n        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);\n        transform.position += movement * moveSpeed * Time.deltaTime;\n    }\n}\n<\/code>\n<\/pre>\n<p>Add the above script to the Player object. This script allows the player object to move using the WASD keys.<\/p>\n<h3>3.2 Creating the Bullet Script<\/h3>\n<p>Next, let&#8217;s write the script for the bullet. First, create a new game object called &#8216;Bullet&#8217; and add a Rigidbody component.<\/p>\n<pre>\n<code>using UnityEngine;\n\npublic class Bullet : MonoBehaviour\n{\n    public float speed = 20f;\n\n    void Start()\n    {\n        Rigidbody rb = GetComponent<rigidbody>();\n        rb.velocity = transform.forward * speed;\n    }\n\n    void OnTriggerEnter(Collider other)\n    {\n        if (other.gameObject.CompareTag(\"Enemy\"))\n        {\n            Destroy(other.gameObject);\n            Destroy(gameObject);\n        }\n    }\n}\n<\/rigidbody><\/code>\n<\/pre>\n<h3>3.3 Implementing the Shooting System<\/h3>\n<p>Now let&#8217;s implement a way for the player to shoot. Add the following code to the PlayerController script:<\/p>\n<pre>\n<code>public GameObject bulletPrefab;\npublic Transform bulletSpawn;\n\nvoid Update()\n{\n    \/\/ Existing movement code\n    ...\n\n    if (Input.GetButtonDown(\"Fire1\"))\n    {\n        Shoot();\n    }\n}\n\nvoid Shoot()\n{\n    Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);\n}\n<\/code>\n<\/pre>\n<p>This code adds functionality to instantiate a bullet each time the player clicks the mouse button. After creating the bullet prefab, link this prefab to the &#8216;bulletPrefab&#8217; variable.<\/p>\n<h2>4. Implementing Invisible Shooting<\/h2>\n<p>Now that the bullet is instantiated, we need to adjust the alpha value using Material to make it invisible. Create an appropriate Material for the prefab and set the alpha value to 0.<\/p>\n<h3>4.1 Setting Up the Bullet Material<\/h3>\n<pre>\n<code>using UnityEngine;\n\npublic class Bullet : MonoBehaviour\n{\n    public float speed = 20f;\n    private Material bulletMaterial;\n\n    void Start()\n    {\n        bulletMaterial = GetComponent<renderer>().material;\n        Color color = bulletMaterial.color;\n        color.a = 0; \/\/ Set the bullet's alpha value to 0 to make it invisible\n        bulletMaterial.color = color;\n\n        Rigidbody rb = GetComponent<rigidbody>();\n        rb.velocity = transform.forward * speed;\n    }\n}\n<\/rigidbody><\/renderer><\/code>\n<\/pre>\n<h2>5. Completing the Game<\/h2>\n<p>Now that all the functions are implemented, when you run the game, you will see the player moving and the bullets being fired invisibly. You can develop this system into a shooting game.<\/p>\n<h3>5.1 Creating Enemies and Game Flow<\/h3>\n<p>You can write an enemy spawner to spawn enemies. Add the following script to the GameManager:<\/p>\n<pre>\n<code>using UnityEngine;\n\npublic class GameManager : MonoBehaviour\n{\n    public GameObject enemyPrefab;\n    public float spawnTime = 2f;\n\n    void Start()\n    {\n        InvokeRepeating(\"SpawnEnemy\", spawnTime, spawnTime);\n    }\n\n    void SpawnEnemy()\n    {\n        Instantiate(enemyPrefab, new Vector3(Random.Range(-5f, 5f), 0.5f, Random.Range(-5f, 5f)), Quaternion.identity);\n    }\n}\n<\/code>\n<\/pre>\n<h2>6. Conclusion<\/h2>\n<p>In this course, you learned how to implement an invisible shooting mechanism in Unity. Utilizing these techniques will greatly assist you in developing various games. In the next course, we will cover more advanced techniques and content.<\/p>\n<p>Thank you for reading to the end. I hope this helps you in your Unity development journey!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this course, we will learn how to implement &#8216;invisible shooting&#8217; using the Unity engine. This course is for those who have a basic understanding of Unity, and it will help if you know the basics of scripting and how to use game objects. 1. Setting Up the Project First, create a new Unity project. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31797\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: Implementing Invisible Shooting&#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-31797","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: Implementing Invisible Shooting - \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\/31797\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: Implementing Invisible Shooting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this course, we will learn how to implement &#8216;invisible shooting&#8217; using the Unity engine. This course is for those who have a basic understanding of Unity, and it will help if you know the basics of scripting and how to use game objects. 1. Setting Up the Project First, create a new Unity project. &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: Implementing Invisible Shooting&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31797\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:03:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:34:40+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: Implementing Invisible Shooting\",\"datePublished\":\"2024-11-01T09:03:01+00:00\",\"dateModified\":\"2024-11-01T11:34:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/\"},\"wordCount\":473,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31797\/\",\"name\":\"Unity Basics Course: Implementing Invisible Shooting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:03:01+00:00\",\"dateModified\":\"2024-11-01T11:34:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31797\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31797\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: Implementing Invisible Shooting\"}]},{\"@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: Implementing Invisible Shooting - \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\/31797\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: Implementing Invisible Shooting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this course, we will learn how to implement &#8216;invisible shooting&#8217; using the Unity engine. This course is for those who have a basic understanding of Unity, and it will help if you know the basics of scripting and how to use game objects. 1. Setting Up the Project First, create a new Unity project. &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: Implementing Invisible Shooting\"","og_url":"https:\/\/atmokpo.com\/w\/31797\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:03:01+00:00","article_modified_time":"2024-11-01T11:34:40+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/31797\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31797\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: Implementing Invisible Shooting","datePublished":"2024-11-01T09:03:01+00:00","dateModified":"2024-11-01T11:34:40+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31797\/"},"wordCount":473,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31797\/","url":"https:\/\/atmokpo.com\/w\/31797\/","name":"Unity Basics Course: Implementing Invisible Shooting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:03:01+00:00","dateModified":"2024-11-01T11:34:40+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31797\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31797\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31797\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: Implementing Invisible Shooting"}]},{"@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\/31797","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=31797"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31797\/revisions"}],"predecessor-version":[{"id":31798,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31797\/revisions\/31798"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}