{"id":32085,"date":"2024-11-01T09:05:33","date_gmt":"2024-11-01T09:05:33","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32085"},"modified":"2024-11-01T11:33:23","modified_gmt":"2024-11-01T11:33:23","slug":"unity-basics-course-what-is-a-conditional-statement","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32085\/","title":{"rendered":"Unity Basics Course: What is a Conditional Statement?"},"content":{"rendered":"<p>Unity is a powerful engine for game development, primarily using the programming language C# to write scripts. Conditional statements play an important role in game development. Through conditional statements, we can control the flow of the program and implement logic that can respond to various situations. In this article, we will explain C# conditional statements in detail, along with example code.<\/p>\n<h2>Concept of Conditional Statements<\/h2>\n<p>A conditional statement is a statement that can branch the execution flow of the program based on whether a given condition is true or false. The conditional statements used in C# mainly include <code>if<\/code>, <code>else<\/code>, <code>else if<\/code>, and <code>switch<\/code>.<\/p>\n<h2>1. if Statement<\/h2>\n<p>The <code>if<\/code> statement executes specific code if the given condition is true. The basic syntax is as follows:<\/p>\n<pre><code>if (condition)\n{\n    \/\/ Code to execute if the condition is true\n}<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>void Update()\n{\n    if (Input.GetKeyDown(KeyCode.Space))\n    {\n        Debug.Log(\"The space key has been pressed.\");\n    }\n}<\/code><\/pre>\n<p>In the above example, a message is printed to the console when the space key is pressed.<\/p>\n<h2>2. else Statement<\/h2>\n<p>The <code>else<\/code> statement defines the code to be executed when the condition of the <code>if<\/code> statement is false. The syntax is as follows:<\/p>\n<pre><code>if (condition)\n{\n    \/\/ Code to execute if the condition is true\n}\nelse\n{\n    \/\/ Code to execute if the condition is false\n}<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>void Update()\n{\n    if (Input.GetKeyDown(KeyCode.Space))\n    {\n        Debug.Log(\"The space key has been pressed.\");\n    }\n    else\n    {\n        Debug.Log(\"The space key has not been pressed.\");\n    }\n}<\/code><\/pre>\n<p>This example prints different messages based on whether the space key was pressed or not.<\/p>\n<h2>3. else if Statement<\/h2>\n<p>The <code>else if<\/code> statement is used to check multiple conditions. The syntax is as follows:<\/p>\n<pre><code>if (condition1)\n{\n    \/\/ Code to execute if condition1 is true\n}\nelse if (condition2)\n{\n    \/\/ Code to execute if condition2 is true\n}\nelse\n{\n    \/\/ Code to execute if all conditions are false\n}<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>void Update()\n{\n    if (Input.GetKeyDown(KeyCode.Alpha1))\n    {\n        Debug.Log(\"The 1 key has been pressed.\");\n    }\n    else if (Input.GetKeyDown(KeyCode.Alpha2))\n    {\n        Debug.Log(\"The 2 key has been pressed.\");\n    }\n    else\n    {\n        Debug.Log(\"Neither the 1 nor the 2 key has been pressed.\");\n    }\n}<\/code><\/pre>\n<p>This example reacts differently based on user input.<\/p>\n<h2>4. switch Statement<\/h2>\n<p>The <code>switch<\/code> statement is useful for checking if a given variable matches one of several values. The syntax is as follows:<\/p>\n<pre><code>switch (variable)\n{\n    case value1:\n        \/\/ Code to execute when it matches value1\n        break;\n    case value2:\n        \/\/ Code to execute when it matches value2\n        break;\n    default:\n        \/\/ Code to execute when none of the cases match\n        break;\n}<\/code><\/pre>\n<h3>Example<\/h3>\n<pre><code>void Update()\n{\n    int score = 10;\n\n    switch (score)\n    {\n        case 10:\n            Debug.Log(\"The score is 10.\");\n            break;\n        case 20:\n            Debug.Log(\"The score is 20.\");\n            break;\n        default:\n            Debug.Log(\"The score is neither 10 nor 20.\");\n            break;\n    }\n}<\/code><\/pre>\n<p>This example prints different messages based on the score.<\/p>\n<h2>Precautions When Using Conditional Statements<\/h2>\n<ul>\n<li>Using nested conditional statements can make the code complex. It is important to maintain a proper logical structure to ensure readability.<\/li>\n<li>Including a lot of code within a conditional statement can reduce efficiency. It is advisable to keep conditional statements concise whenever possible.<\/li>\n<li>It is advisable to refactor the code to reduce unnecessary conditional statements. For example, using boolean variables can be a method.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Conditional statements are a very important element in structuring game logic in Unity. When used correctly, they can enrich the interactions in the game and maximize the user experience. This tutorial explained the basic concepts and usage of conditional statements. It is recommended to practice with various examples for a deeper understanding in the future.<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/index.html\">Unity Scripting API<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/keywords\/if-else\">C# if-else Reference<\/a><\/li>\n<li><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/operators\/switch\">C# switch Reference<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Unity is a powerful engine for game development, primarily using the programming language C# to write scripts. Conditional statements play an important role in game development. Through conditional statements, we can control the flow of the program and implement logic that can respond to various situations. In this article, we will explain C# conditional statements &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32085\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: What is a Conditional Statement?&#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-32085","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 a Conditional Statement? - \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\/32085\/\" \/>\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 a Conditional Statement? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Unity is a powerful engine for game development, primarily using the programming language C# to write scripts. Conditional statements play an important role in game development. Through conditional statements, we can control the flow of the program and implement logic that can respond to various situations. In this article, we will explain C# conditional statements &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: What is a Conditional Statement?&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32085\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:05:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:33:23+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\/32085\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32085\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: What is a Conditional Statement?\",\"datePublished\":\"2024-11-01T09:05:33+00:00\",\"dateModified\":\"2024-11-01T11:33:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32085\/\"},\"wordCount\":375,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32085\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32085\/\",\"name\":\"Unity Basics Course: What is a Conditional Statement? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:05:33+00:00\",\"dateModified\":\"2024-11-01T11:33:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32085\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32085\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32085\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: What is a Conditional Statement?\"}]},{\"@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 a Conditional Statement? - \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\/32085\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: What is a Conditional Statement? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Unity is a powerful engine for game development, primarily using the programming language C# to write scripts. Conditional statements play an important role in game development. Through conditional statements, we can control the flow of the program and implement logic that can respond to various situations. In this article, we will explain C# conditional statements &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: What is a Conditional Statement?\"","og_url":"https:\/\/atmokpo.com\/w\/32085\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:05:33+00:00","article_modified_time":"2024-11-01T11:33:23+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\/32085\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32085\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: What is a Conditional Statement?","datePublished":"2024-11-01T09:05:33+00:00","dateModified":"2024-11-01T11:33:23+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32085\/"},"wordCount":375,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32085\/","url":"https:\/\/atmokpo.com\/w\/32085\/","name":"Unity Basics Course: What is a Conditional Statement? - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:05:33+00:00","dateModified":"2024-11-01T11:33:23+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32085\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32085\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32085\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: What is a Conditional Statement?"}]},{"@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\/32085","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=32085"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32085\/revisions"}],"predecessor-version":[{"id":32086,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32085\/revisions\/32086"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}