{"id":31789,"date":"2024-11-01T09:02:55","date_gmt":"2024-11-01T09:02:55","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31789"},"modified":"2024-11-01T11:34:42","modified_gmt":"2024-11-01T11:34:42","slug":"unity-basics-course-array-declaration","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31789\/","title":{"rendered":"Unity Basics Course: Array Declaration"},"content":{"rendered":"<p><body><\/p>\n<p>Unity is a very popular platform for game development, providing various features to help developers create games efficiently. Among these, the &#8216;array&#8217;, which is fundamental to programming, plays an important role in understanding data structures. This article will explain in detail how to declare and use arrays in Unity.<\/p>\n<h2>1. Basic Concept of Arrays<\/h2>\n<p>An Array is a data structure that can store multiple values of the same data type. By using arrays, multiple data can be easily managed and accessed. For example, they are useful for managing several enemy characters or storing a list of items.<\/p>\n<h3>1.1 Advantages of Arrays<\/h3>\n<ul>\n<li><strong>Memory Efficiency:<\/strong> Using fixed-size arrays can result in efficient memory usage.<\/li>\n<li><strong>Data Access Speed:<\/strong> Quick access to data through indices.<\/li>\n<li><strong>Sorting and Searching:<\/strong> Easy implementation of sorting and searching algorithms using arrays.<\/li>\n<\/ul>\n<h2>2. Declaring Arrays in Unity<\/h2>\n<p>In Unity, arrays can be declared using C#. The method for declaring arrays in C# is as follows.<\/p>\n<h3>2.1 Array Declaration and Initialization<\/h3>\n<p>To declare an array, use the data type and square brackets []. The following is how to declare and initialize an integer array:<\/p>\n<pre><code>int[] numbers = new int[5]; \/\/ Declare an integer array of size 5<\/code><\/pre>\n<p>The elements of the array can be accessed using indices, which start from 0.<\/p>\n<pre><code>numbers[0] = 10; \/\/ Assign a value to the first element<\/code><\/pre>\n<h3>2.2 Array Initialization Methods<\/h3>\n<p>You can also initialize an array while declaring it:<\/p>\n<pre><code>int[] numbers = {1, 2, 3, 4, 5}; \/\/ Declare and initialize the array at the same time<\/code><\/pre>\n<h2>3. Uses of Arrays<\/h2>\n<p>Arrays can be effectively used in various situations. Generally, in Unity, game objects, sprites, sounds, etc., can be managed in arrays.<\/p>\n<h3>3.1 Game Object Arrays<\/h3>\n<p>Managing game objects in an array allows for easy access later and batch processing using loops. Here is an example of managing multiple enemy characters in an array:<\/p>\n<pre><code>public GameObject[] enemies; \/\/ Declare a game object array<\/code><\/pre>\n<h3>3.2 Iteration through Arrays<\/h3>\n<p>You can repeatedly perform actions on each element of the array. The following is code that changes the position of enemy characters:<\/p>\n<pre><code>foreach(GameObject enemy in enemies) {\n    enemy.transform.position += Vector3.forward; \/\/ Move all enemy characters forward\n}\n<\/code><\/pre>\n<h2>4. Various Types of Arrays<\/h2>\n<p>C# supports various kinds of arrays. In addition to one-dimensional arrays, you can use multi-dimensional arrays and Jagged Arrays.<\/p>\n<h3>4.1 Multi-dimensional Arrays<\/h3>\n<p>Multi-dimensional arrays can store data of multiple dimensions. An example of a two-dimensional array is as follows:<\/p>\n<pre><code>int[,] grid = new int[3, 3]; \/\/ 3x3 integer two-dimensional array<\/code><\/pre>\n<h3>4.2 Jagged Arrays<\/h3>\n<p>A Jagged Array is an array of arrays, where each array can have a different length:<\/p>\n<pre><code>int[][] jaggedArray = new int[3][]; \/\/ Declare a Jagged Array\njaggedArray[0] = new int[2] { 1, 2 }; \/\/ First array\njaggedArray[1] = new int[3] { 3, 4, 5 }; \/\/ Second array\njaggedArray[2] = new int[1] { 6 }; \/\/ Third array\n<\/code><\/pre>\n<h2>5. Characteristics and Cautions of Arrays<\/h2>\n<p>There are several important things to know before using arrays:<\/p>\n<ul>\n<li><strong>Fixed Size:<\/strong> Once declared, the size of an array cannot be changed. If necessary, a new array must be created.<\/li>\n<li><strong>Index Range:<\/strong> Array indices start from 0, so it must be used cautiously to avoid out-of-bounds errors.<\/li>\n<li><strong>Initialization:<\/strong> Declared arrays are initialized with default values, but if they are not explicitly initialized, unintended results may occur.<\/li>\n<\/ul>\n<h2>6. Differences Between Arrays and Lists<\/h2>\n<p>A similar concept to arrays is <strong>Lists<\/strong>. Lists are a dynamic data structure that can change in size, and they have the following differences from arrays:<\/p>\n<ul>\n<li>Arrays have a fixed size, while lists can change size by adding or removing elements.<\/li>\n<li>Lists provide various methods that are advantageous for data processing.<\/li>\n<\/ul>\n<h2>7. Conclusion<\/h2>\n<p>Arrays are a very important element in Unity development. They help manage various game elements easily and efficiently, so it is essential to understand them well. This tutorial covered the basic concepts of arrays, their declaration, initialization, and usage.<\/p>\n<p>Now take a step further in game development by utilizing arrays!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity is a very popular platform for game development, providing various features to help developers create games efficiently. Among these, the &#8216;array&#8217;, which is fundamental to programming, plays an important role in understanding data structures. This article will explain in detail how to declare and use arrays in Unity. 1. Basic Concept of Arrays An &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31789\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: Array Declaration&#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-31789","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: Array Declaration - \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\/31789\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: Array Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Unity is a very popular platform for game development, providing various features to help developers create games efficiently. Among these, the &#8216;array&#8217;, which is fundamental to programming, plays an important role in understanding data structures. This article will explain in detail how to declare and use arrays in Unity. 1. Basic Concept of Arrays An &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: Array Declaration&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31789\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:02:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:34:42+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\/31789\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31789\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: Array Declaration\",\"datePublished\":\"2024-11-01T09:02:55+00:00\",\"dateModified\":\"2024-11-01T11:34:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31789\/\"},\"wordCount\":526,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31789\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31789\/\",\"name\":\"Unity Basics Course: Array Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:02:55+00:00\",\"dateModified\":\"2024-11-01T11:34:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31789\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31789\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31789\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: Array Declaration\"}]},{\"@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: Array Declaration - \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\/31789\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: Array Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Unity is a very popular platform for game development, providing various features to help developers create games efficiently. Among these, the &#8216;array&#8217;, which is fundamental to programming, plays an important role in understanding data structures. This article will explain in detail how to declare and use arrays in Unity. 1. Basic Concept of Arrays An &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: Array Declaration\"","og_url":"https:\/\/atmokpo.com\/w\/31789\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:02:55+00:00","article_modified_time":"2024-11-01T11:34:42+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\/31789\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31789\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: Array Declaration","datePublished":"2024-11-01T09:02:55+00:00","dateModified":"2024-11-01T11:34:42+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31789\/"},"wordCount":526,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31789\/","url":"https:\/\/atmokpo.com\/w\/31789\/","name":"Unity Basics Course: Array Declaration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:02:55+00:00","dateModified":"2024-11-01T11:34:42+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31789\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31789\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31789\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: Array Declaration"}]},{"@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\/31789","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=31789"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31789\/revisions"}],"predecessor-version":[{"id":31790,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31789\/revisions\/31790"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}