{"id":135,"date":"2020-06-15T00:12:03","date_gmt":"2020-06-15T00:12:03","guid":{"rendered":"https:\/\/lucyestela.com\/dev\/?p=135"},"modified":"2021-03-02T03:00:05","modified_gmt":"2021-03-02T03:00:05","slug":"call-sequence-of-class-methods","status":"publish","type":"post","link":"https:\/\/lucyestela.com\/dev\/unity\/call-sequence-of-class-methods\/","title":{"rendered":"Call Sequence of Class Methods &#8211; Unity"},"content":{"rendered":"<div class=\"boldgrid-section\">\n<div class=\"container\">\n<div class=\"row\">\n<div class=\"col-md-12 col-xs-12 col-sm-12\">\n<p>Right, so classes have a number of methods in them and it can get a bit confusing as to when each of them are called, especially when you require a very specific sequence of events to occur.<\/p>\n<p class=\"\">So let&#8217;s say that you are instantiating a prefab from a class method.<\/p>\n<pre class=\"\"><span style=\"font-family: Menlo;\"> <span style=\"color: #3363a4;\">yourPrefab<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">yPre<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">= Instantiate(<span style=\"color: #3363a4;\">yourPrefab<\/span>, transform.position, transform.rotation);<\/span><\/span><\/pre>\n<pre class=\"codeExampleCS\">&nbsp;<\/pre>\n<pre class=\"\"><span style=\"font-family: Menlo;\"><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">SpawnAsteroid<\/span><span style=\"color: #222222;\">();<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">ast<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">gameObject<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">name<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">=<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #db7100;\">\"Asteroid_\"<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">+<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">i<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">ToString<\/span><span style=\"color: #222222;\">(<\/span><span style=\"color: #db7100;\">\"00\"<\/span><span style=\"color: #222222;\">);<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #888a85;\">\/\/&nbsp;Find&nbsp;a&nbsp;good&nbsp;location&nbsp;for&nbsp;the&nbsp;Asteroid&nbsp;to&nbsp;spawn<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #3363a4;\">Vector3<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">pos<\/span><span style=\"color: #222222;\">;<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #009695;\">do<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">{<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">pos<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">=<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #3363a4;\">ScreenBounds<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">RANDOM_ON_SCREEN_LOC<\/span><span style=\"color: #222222;\">;<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">}<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #009695;\">while<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">((<\/span><span style=\"color: #222222;\">pos<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">-<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #3363a4;\">PlayerShip<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">POSITION<\/span><span style=\"color: #222222;\">)<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">magnitude<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">&lt;<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">MIN_ASTEROID_DIST_FROM_PLAYER_SHIP<\/span><span style=\"color: #222222;\">);<\/span>\r\n\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">ast<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">transform<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">position<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">=<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">pos<\/span><span style=\"color: #222222;\">;<\/span>\r\n<span style=\"color: #222222;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #222222;\">ast<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">size<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">=<\/span><span style=\"color: #222222;\">&nbsp;<\/span><span style=\"color: #222222;\">asteroidsSO<\/span><span style=\"color: #222222;\">.<\/span><span style=\"color: #222222;\">initialSize<\/span><span style=\"color: #222222;\">;<\/span><\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Right, so classes have a number of methods in them and it can get a bit confusing as to when each of them are called, especially when you require a very specific sequence of events to occur. So let&#8217;s say that you are instantiating a prefab from a class method. yourPrefab&nbsp;yPre&nbsp;= Instantiate(yourPrefab, transform.position, transform.rotation); &nbsp; &#8230; <a title=\"Call Sequence of Class Methods &#8211; Unity\" class=\"read-more\" href=\"https:\/\/lucyestela.com\/dev\/unity\/call-sequence-of-class-methods\/\" aria-label=\"More on Call Sequence of Class Methods &#8211; Unity\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"bgseo_title":"","bgseo_description":"","bgseo_robots_index":"","bgseo_robots_follow":"","footnotes":""},"categories":[58],"tags":[36,4],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-unity","tag-method","tag-unity"],"_links":{"self":[{"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":2,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/posts\/135\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lucyestela.com\/dev\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}