{"id":1492,"date":"2022-03-17T16:47:30","date_gmt":"2022-03-17T16:47:30","guid":{"rendered":"https:\/\/golemitegames.com\/?post_type=docs&#038;p=1492"},"modified":"2022-03-17T20:19:06","modified_gmt":"2022-03-17T20:19:06","password":"","slug":"gridselector","status":"publish","type":"docs","link":"https:\/\/golemitegames.com\/index.php\/docs\/gridselector\/","title":{"rendered":"GridSelector"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public void ChangeObjMat(GameObject obj, Material newMat)<\/strong><\/strong><\/h2>\n\n\n\n<p>This will loop through all children of the obj including itself and through all assigned materials and assign the newMat to each of them.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Changes the obj material to something else.\nGridSelector gridSelector;\n\nvoid Start() \n{\n    gridSelector.ChangeObjMat(myObjectToChange, invalidMaterial);\n} \n<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void DeselectPreview()<\/strong><\/h2>\n\n\n\n<p>This function destroys the preview object from the hierarchy and sets the object to place as null.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Remove the previewing of the object assigned when pressing escape.\nGridSelector gridSelector;\n\nvoid Update() \n{\n    if(Input.GetKeyDown(KeyCode.Escape))\n    {\n        gridSelector.DeselectPreview();\n    } \n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void SetGameObjectToPlace(GameObject obj)<\/strong><\/h2>\n\n\n\n<p>This simply takes in the obj, and sets it for the Grid Selector to preview or place the object.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Takes an object from a button to place on the grid selector.\nGridSelector gridSelector;\n\n\/\/The prefab to send to the grid selector to place\npublic GameObject prefab;\n\nvoid Awake() \n{\n    btn = GetComponent&lt;Button&gt;();\n}\nvoid Start() \n{\n    btn.onClick.AddListener(() =&gt; {\n        gridSelector.SetGameObjectToPlace(prefab); \n    });\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public Vector3 GetSelectorPosition()<\/strong><\/h2>\n\n\n\n<p>This returns the current clamped position of the grid selector. This value can then be used to find out if the cell is free using gridSquare.CheckCellStatus(Vector3 cellPos).<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Debugs the current clamped grid selector position\nGridSelector gridSelector;\n\nvoid Update() \n{\n    Debug.Log(gridSelector.GetSelectorPosition());\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>public void ChangeObjMat(GameObject obj, Material newMat) This will loop through all children of the obj including itself and through all assigned materials and assign the newMat to each of them. public void DeselectPreview() This function destroys the preview object from the hierarchy and sets the object to place as null. public void SetGameObjectToPlace(GameObject obj) This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"doc_category":[28],"doc_tag":[],"class_list":["post-1492","docs","type-docs","status-publish","hentry","doc_category-scripting"],"acf":[],"aioseo_notices":[],"year_month":"2026-04","word_count":201,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"rickitz5h","author_nicename":"rickitz5h","author_url":"https:\/\/golemitegames.com\/index.php\/author\/rickitz5h\/"},"doc_category_info":[{"term_name":"Scripting","term_url":"https:\/\/golemitegames.com\/index.php\/docs-category\/scripting\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/comments?post=1492"}],"version-history":[{"count":9,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1492\/revisions"}],"predecessor-version":[{"id":1512,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1492\/revisions\/1512"}],"wp:attachment":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/media?parent=1492"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_category?post=1492"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_tag?post=1492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}