{"id":31886,"date":"2024-11-01T09:03:50","date_gmt":"2024-11-01T09:03:50","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31886"},"modified":"2024-11-01T11:34:17","modified_gmt":"2024-11-01T11:34:17","slug":"unity-basics-course-registering-parent-class","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31886\/","title":{"rendered":"Unity Basics Course: Registering Parent Class"},"content":{"rendered":"<p><body><\/p>\n<p>In this lecture, we will understand the concept of parent class registration in Unity and how it is utilized in actual game development. Classes are a crucial concept in object-oriented programming, and the relationship between parent classes and child classes plays a significant role in enhancing code reusability and maintainability.<\/p>\n<h2>1. Object-Oriented Programming and Classes<\/h2>\n<p>Object-Oriented Programming (OOP) is one of the software development paradigms that encapsulates data into units called objects. A class is a blueprint for creating objects, defining their state (attributes) and behavior (methods).<\/p>\n<h3>1.1 Basic Understanding of Classes and Objects<\/h3>\n<p>A class is a framework for creating objects. For example, if we define a class called Car, we can create multiple Car objects based on this class:<\/p>\n<pre><code>class Car {\n        public string color;\n        public string model;\n\n        public void Drive() {\n            Debug.Log(\"The car is driving\");\n        }\n    }\n    <\/code><\/pre>\n<p>In the above class, <code>color<\/code> and <code>model<\/code> are attributes, while <code>Drive<\/code> is a method. This allows us to create multiple <code>Car<\/code> objects and utilize their attributes and methods.<\/p>\n<h3>1.2 Importance of Inheritance<\/h3>\n<p>Inheritance is a vital feature that creates relationships between classes. A parent class (base class) can pass its attributes and methods to a child class (derived class). This characteristic helps reduce code duplication and facilitates maintenance.<\/p>\n<h2>2. Defining a Parent Class<\/h2>\n<p>To define a parent class, we use the <code>class<\/code> keyword to create a class. Let&#8217;s examine this through the example below:<\/p>\n<pre><code>class Animal {\n        public string name;\n\n        public void Speak() {\n            Debug.Log(name + \" says hello!\");\n        }\n    }\n    <\/code><\/pre>\n<p>The above code defines a parent class called <code>Animal<\/code>. This class has an attribute called <code>name<\/code> and a method called <code>Speak<\/code>.<\/p>\n<h3>2.1 Creating a Child Class<\/h3>\n<p>To create a child class that inherits from a parent class, we use the <code>:<\/code> symbol. The example below shows a <code>Dog<\/code> class inheriting from the <code>Animal<\/code> class:<\/p>\n<pre><code>class Dog : Animal {\n        public void Bark() {\n            Debug.Log(name + \" says woof!\");\n        }\n    }\n    <\/code><\/pre>\n<p>The above code demonstrates that the <code>Dog<\/code> class inherits attributes and methods from the <code>Animal<\/code> class.<\/p>\n<h2>3. Registering the Parent Class<\/h2>\n<p>The process of registering a parent class in Unity is very simple. Create a <code>Scripts<\/code> folder in the Unity Editor and write a C# script to define the parent class. Then, create a class that inherits from the parent class in the code and connect it to a game object for use.<\/p>\n<h3>3.1 Creating the Script<\/h3>\n<p>To register the parent class in Unity, create a file named <code>Animal.cs<\/code>:<\/p>\n<pre><code>using UnityEngine;\n\n    public class Animal {\n        public string name;\n\n        public void Speak() {\n            Debug.Log(name + \" says hello!\");\n        }\n    }\n    <\/code><\/pre>\n<h3>3.2 Connecting the Child Class<\/h3>\n<p>Create a child class called <code>Dog.cs<\/code> that inherits from the <code>Animal<\/code> class:<\/p>\n<pre><code>using UnityEngine;\n\n    public class Dog : Animal {\n        public void Bark() {\n            Debug.Log(name + \" says woof!\");\n        }\n    }\n    <\/code><\/pre>\n<h3>3.3 Using the Script<\/h3>\n<p>Now, write a new C# script to connect the <code>Dog<\/code> class to a game object and create an instance using the <code>Dog<\/code> class:<\/p>\n<pre><code>using UnityEngine;\n\n    public class DogController : MonoBehaviour {\n        private Dog myDog;\n\n        void Start() {\n            myDog = new Dog();\n            myDog.name = \"Buddy\";\n            myDog.Speak();\n            myDog.Bark();\n        }\n    }\n    <\/code><\/pre>\n<h2>4. Practicing Parent Class Registration<\/h2>\n<p>Now that you have learned how to register a parent class, let&#8217;s create a simple project using this knowledge. Follow the steps below for practice:<\/p>\n<h3>4.1 Creating a New C# Script<\/h3>\n<p>In the Unity Editor, create a new C# script and write the following code:<\/p>\n<pre><code>public class Cat : Animal {\n        public void Meow() {\n            Debug.Log(name + \" says meow!\");\n        }\n    }\n    <\/code><\/pre>\n<h3>4.2 Creating Game Objects and Connecting Scripts<\/h3>\n<p>Create a game object and connect the <code>DogController<\/code> script that you wrote above. You can also connect and use the <code>Cat<\/code> class through this script.<\/p>\n<h2>5. Utilizing Inheritance<\/h2>\n<p>Inheritance through parent and child classes offers many advantages. It increases code reusability and creates a maintainable structure. Additionally, leveraging inheritance enhances code readability and significantly aids in extending functionality.<\/p>\n<h3>5.1 Polymorphism<\/h3>\n<p>In game engines like Unity, polymorphism allows you to manage various child classes of a parent class in arrays or collections. This enables efficient handling of objects with diverse behaviors:<\/p>\n<pre><code>public class AnimalManager : MonoBehaviour {\n        private Animal[] animals;\n\n        void Start() {\n            animals = new Animal[2];\n            animals[0] = new Dog { name = \"Buddy\" };\n            animals[1] = new Cat { name = \"Kitty\" };\n\n            foreach (Animal animal in animals) {\n                animal.Speak();\n            }\n        }\n    }\n    <\/code><\/pre>\n<h2>6. Conclusion<\/h2>\n<p>In this lecture, we learned in detail about the concept and implementation of parent class registration in Unity. We understood that using the inheritance feature of object-oriented programming allows effective utilization of parent class attributes and methods in child classes. This structure enhances code reusability and maintainability, which will greatly assist in managing multiple characters and objects in game development.<\/p>\n<div class=\"note\">\n<strong>Note:<\/strong> For more in-depth learning, please refer to the official Unity documentation or books related to object-oriented programming.\n    <\/div>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lecture, we will understand the concept of parent class registration in Unity and how it is utilized in actual game development. Classes are a crucial concept in object-oriented programming, and the relationship between parent classes and child classes plays a significant role in enhancing code reusability and maintainability. 1. Object-Oriented Programming and Classes &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31886\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Unity Basics Course: Registering Parent Class&#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-31886","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: Registering Parent Class - \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\/31886\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity Basics Course: Registering Parent Class - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"In this lecture, we will understand the concept of parent class registration in Unity and how it is utilized in actual game development. Classes are a crucial concept in object-oriented programming, and the relationship between parent classes and child classes plays a significant role in enhancing code reusability and maintainability. 1. Object-Oriented Programming and Classes &hellip; \ub354 \ubcf4\uae30 &quot;Unity Basics Course: Registering Parent Class&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31886\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:03:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:34:17+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\/31886\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31886\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Unity Basics Course: Registering Parent Class\",\"datePublished\":\"2024-11-01T09:03:50+00:00\",\"dateModified\":\"2024-11-01T11:34:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31886\/\"},\"wordCount\":601,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Unity Basic\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31886\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31886\/\",\"name\":\"Unity Basics Course: Registering Parent Class - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:03:50+00:00\",\"dateModified\":\"2024-11-01T11:34:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31886\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31886\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31886\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity Basics Course: Registering Parent Class\"}]},{\"@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: Registering Parent Class - \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\/31886\/","og_locale":"ko_KR","og_type":"article","og_title":"Unity Basics Course: Registering Parent Class - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"In this lecture, we will understand the concept of parent class registration in Unity and how it is utilized in actual game development. Classes are a crucial concept in object-oriented programming, and the relationship between parent classes and child classes plays a significant role in enhancing code reusability and maintainability. 1. Object-Oriented Programming and Classes &hellip; \ub354 \ubcf4\uae30 \"Unity Basics Course: Registering Parent Class\"","og_url":"https:\/\/atmokpo.com\/w\/31886\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:03:50+00:00","article_modified_time":"2024-11-01T11:34:17+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\/31886\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31886\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Unity Basics Course: Registering Parent Class","datePublished":"2024-11-01T09:03:50+00:00","dateModified":"2024-11-01T11:34:17+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31886\/"},"wordCount":601,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Unity Basic"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31886\/","url":"https:\/\/atmokpo.com\/w\/31886\/","name":"Unity Basics Course: Registering Parent Class - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:03:50+00:00","dateModified":"2024-11-01T11:34:17+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31886\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31886\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31886\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Unity Basics Course: Registering Parent Class"}]},{"@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\/31886","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=31886"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31886\/revisions"}],"predecessor-version":[{"id":31887,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31886\/revisions\/31887"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}