{"id":32071,"date":"2024-11-01T09:05:25","date_gmt":"2024-11-01T09:05:25","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32071"},"modified":"2024-11-01T11:33:26","modified_gmt":"2024-11-01T11:33:26","slug":"unity-basics-course-what-is-an-array","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32071\/","title":{"rendered":"Unity Basics Course: What is an Array?"},"content":{"rendered":"<p><body><\/p>\n<p>When programming in Unity, you can use various data structures. Among these, arrays are a very important data structure and are utilized in almost every part of game development. In this tutorial, we will explore the concept of arrays, how to use them, and how to leverage arrays in Unity in detail.<\/p>\n<h2>1. Definition of Arrays<\/h2>\n<p>An array is a data structure that can collectively store multiple data items of the same data type. Each element of the array can be accessed through an index, which starts from 0. For example, an array of 5 integers has indices ranging from 0 to 4.<\/p>\n<h3>1.1 Characteristics of Arrays<\/h3>\n<ul>\n<li>Fixed Size: When creating an array, you must define its size, and once set, the size cannot be changed.<\/li>\n<li>Continuous Memory Space: The elements of the array are stored contiguously in memory.<\/li>\n<li>Access through Index: Each element can be accessed directly through its index, allowing for quick data retrieval.<\/li>\n<\/ul>\n<h2>2. How to Use Arrays in Unity<\/h2>\n<p>In Unity, C# is primarily used, and arrays can be used to store and manage various forms of data. Below, we will learn how to declare and use arrays in Unity.<\/p>\n<h3>2.1 Declaring an Array<\/h3>\n<p>Declaring an array is simple. You define the array using the data type and square brackets.<\/p>\n<pre><code>int[] numbers; \/\/ Declaration of an integer array<\/code><\/pre>\n<h3>2.2 Initializing an Array<\/h3>\n<p>After declaring an array, you must initialize it in order to use it. Initialization involves specifying the size of the array and assigning values to it.<\/p>\n<pre><code>numbers = new int[5]; \/\/ Initialize an integer array of size 5<\/code><\/pre>\n<h3>2.3 Assigning Values to an Array<\/h3>\n<p>When assigning values to an initialized array, you use indices. The following example shows how to assign values to an array.<\/p>\n<pre><code>numbers[0] = 10;\nnumbers[1] = 20;\nnumbers[2] = 30;\nnumbers[3] = 40;\nnumbers[4] = 50;<\/code><\/pre>\n<p>You can also initialize an array with values at the time of declaration.<\/p>\n<pre><code>int[] numbers = {10, 20, 30, 40, 50};<\/code><\/pre>\n<h3>2.4 Accessing Array Elements<\/h3>\n<p>Array elements can be accessed using their indices. Below is an example of accessing the first element of an array.<\/p>\n<pre><code>int firstNumber = numbers[0];  \/\/ The value of the first element is 10<\/code><\/pre>\n<h3>2.5 Checking the Size of an Array<\/h3>\n<p>The size of an array can be checked using the <code>Length<\/code> property.<\/p>\n<pre><code>int length = numbers.Length; \/\/ length will be 5.<\/code><\/pre>\n<h2>3. Types of Arrays<\/h2>\n<p>In Unity, arrays are classified into primitive arrays and multidimensional arrays. Let&#8217;s take a closer look at each type.<\/p>\n<h3>3.1 Primitive Arrays<\/h3>\n<p>Primitive arrays are arrays composed of values of the same data type. The most commonly used primitive arrays include the following:<\/p>\n<ul>\n<li>Integer (int)<\/li>\n<li>Floating point (float)<\/li>\n<li>Character (char)<\/li>\n<li>Boolean (bool)<\/li>\n<\/ul>\n<h3>3.2 Multidimensional Arrays<\/h3>\n<p>Multidimensional arrays include arrays within arrays, such as 2D and 3D arrays. For example, a 2D array can store data in a grid format.<\/p>\n<pre><code>int[,] grid = new int[3, 3]; \/\/ Declaration of a 3x3 2D array<\/code><\/pre>\n<p>When accessing elements in a multidimensional array, you need to specify the row and column.<\/p>\n<pre><code>grid[0, 0] = 1; \/\/ Store 1 in the first row and first column<\/code><\/pre>\n<h2>4. Iterating and Searching in Arrays<\/h2>\n<p>Methods for iterating and searching through array elements are also important. You can use loops to access all elements of the array.<\/p>\n<h3>4.1 Iterating through an Array Using a for Loop<\/h3>\n<pre><code>for (int i = 0; i &lt; numbers.Length; i++) {\n    Debug.Log(numbers[i]);\n}<\/code><\/pre>\n<h3>4.2 Iterating through an Array Using a foreach Loop<\/h3>\n<p>You can also use the <code>foreach<\/code> loop for a more convenient way to iterate over the elements of an array.<\/p>\n<pre><code>foreach (int number in numbers) {\n    Debug.Log(number);\n}<\/code><\/pre>\n<h3>4.3 Searching an Array<\/h3>\n<p>To find a specific element in an array, you can use loops and conditionals. The example below shows how to search for 30 in an array.<\/p>\n<pre><code>int target = 30;\nbool found = false;\nfor (int i = 0; i &lt; numbers.Length; i++) {\n    if (numbers[i] == target) {\n        found = true;\n        break;\n    }\n}\nif (found) {\n    Debug.Log(\"Found: \" + target);\n}<\/code><\/pre>\n<h2>5. Useful Features of Arrays<\/h2>\n<p>Arrays are more than just a means of storing data; they can be utilized in various ways in game development. Here are a few examples of the utility of arrays.<\/p>\n<h3>5.1 Object Management<\/h3>\n<p>In Unity, you can manage game objects with arrays for batch processing. For example, when placing multiple enemies, using an array can make it more efficient.<\/p>\n<pre><code>GameObject[] enemies = new GameObject[5];\n\/\/ Add enemy objects to the array\nenemies[0] = enemy1;\nenemies[1] = enemy2;\n\/\/ ... omitted<\/code><\/pre>\n<h3>5.2 Score System<\/h3>\n<p>You can also use arrays to store game scores. You can keep track of the scores for each level in an array and display them to the player.<\/p>\n<pre><code>int[] scores = new int[10]; \/\/ Scores for 10 levels<\/code><\/pre>\n<h3>5.3 Animation Management<\/h3>\n<p>You can manage several animation clips in an array for easy access and transition when needed.<\/p>\n<pre><code>AnimationClip[] animations = new AnimationClip[3]; \/\/ 3 animation clips<\/code><\/pre>\n<h2>6. Limitations and Alternatives of Arrays<\/h2>\n<p>While arrays are convenient, they have some limitations. You cannot dynamically change the size of an array, and you cannot store different data types together. To overcome these limitations, C# provides dynamic data structures known as collections.<\/p>\n<h3>6.1 Using List<t><\/h3>\n<p>The most representative collection is <code>List<t><\/code>. A <code>List<\/code> is similar to an array, but it can change size dynamically and can store different data types.<\/p>\n<pre><code>List<int> numbersList = new List<int>(); \/\/ List Declaration<\/code><\/pre>\n<h3>6.2 Using Dictionary<tkey, tvalue><\/h3>\n<p>Another collection frequently used in Unity is <code>Dictionary<\/code>. This structure is useful for storing data in pairs of keys and values.<\/p>\n<pre><code>Dictionary<string, GameObject> enemiesDict = new Dictionary<string, GameObject>();<\/code><\/pre>\n<h2>7. Conclusion<\/h2>\n<p>Arrays are a very important element in Unity development, providing ways to efficiently manage and use data. I hope this tutorial helped you understand the basic concepts of arrays and how to use them in Unity. By utilizing arrays appropriately, you can write more efficient and organized code in game development. In the next tutorial, we will introduce more diverse data structures and algorithms.<\/p>\n<p>If you encounter any issues or have questions, please leave a comment. Happy Coding!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When programming in Unity, you can use various data structures. Among these, arrays are a very important data structure and are utilized in almost every part of game development. In this tutorial, we will explore the concept of arrays, how to use them, and how to leverage arrays in Unity in detail. 1. Definition of &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32071\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: What is an Array?&#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-32071","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: What is an Array? - \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\/32071\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: What is an Array? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"When programming in Unity, you can use various data structures. Among these, arrays are a very important data structure and are utilized in almost every part of game development. In this tutorial, we will explore the concept of arrays, how to use them, and how to leverage arrays in Unity in detail. 1. Definition of &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: What is an Array?&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32071\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:05:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:26+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=\"5\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: What is an Array?\",\"datePublished\":\"2024-11-01T09:05:25+00:00\",\"dateModified\":\"2024-11-01T11:33:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/\"},\"wordCount\":785,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32071\/\",\"name\":\"Unity Basics Course: What is an Array? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:05:25+00:00\",\"dateModified\":\"2024-11-01T11:33:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32071\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32071\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: What is an Array?\"}]},{\"@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: What is an Array? - \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\/32071\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: What is an Array? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"When programming in Unity, you can use various data structures. Among these, arrays are a very important data structure and are utilized in almost every part of game development. In this tutorial, we will explore the concept of arrays, how to use them, and how to leverage arrays in Unity in detail. 1. Definition of &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: What is an Array?\"","og_url":"https:\/\/atmokpo.com\/w\/32071\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:05:25+00:00","article_modified_time":"2024-11-01T11:33:26+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":"5\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32071\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32071\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: What is an Array?","datePublished":"2024-11-01T09:05:25+00:00","dateModified":"2024-11-01T11:33:26+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32071\/"},"wordCount":785,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32071\/","url":"https:\/\/atmokpo.com\/w\/32071\/","name":"Unity Basics Course: What is an Array? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:05:25+00:00","dateModified":"2024-11-01T11:33:26+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32071\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32071\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32071\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: What is an Array?"}]},{"@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\/32071","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=32071"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32071\/revisions"}],"predecessor-version":[{"id":32072,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32071\/revisions\/32072"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}