{"id":1456,"date":"2022-03-17T15:59:26","date_gmt":"2022-03-17T15:59:26","guid":{"rendered":"https:\/\/golemitegames.com\/?post_type=docs&#038;p=1456"},"modified":"2022-03-17T20:20:31","modified_gmt":"2022-03-17T20:20:31","password":"","slug":"scripting-2","status":"publish","type":"docs","link":"https:\/\/golemitegames.com\/index.php\/docs\/scripting-2\/","title":{"rendered":"GridSquare"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public bool CheckCellStatus(Vector3 cellPos)<\/strong><\/h2>\n\n\n\n<p>This function returns true if the given key (cellPos) is found in the dictionary and that position&#8217;s value is null. It will return false if that keys value is any object except for null. If the value is null, it means the cell is marked as empty, if it is anything else, the cell is still marked as full. <\/p>\n\n\n\n<p>Note the keys entered into the dictionary are the cell position and not the point position. For example, if placing an object in a newly created grid with a cell size of 1, at its first cell, the cell position will be Vector3(0.5f, 0, 0.5f). This is because objects are placed in the centre of each cell. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Checks the first cell if cell size is 1. \nGridSquare myGrid;\n\nvoid Start() \n{\n    if(myGrid.CheckCellStatus(new Vector3(0.5f, 0, 0.5f)))\n    {\n        Debug.Log(&quot;This cell is empty&quot;);\n    }\n    else \n    {\n        Debug.Log(&quot;This cell is full&quot;);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong>public void ChangeCellStatus(Vector3 cellPos, GameObject obj)<\/strong><\/h2>\n\n\n\n<p>This will assign a value(obj) to the key(cellPos) provided. Thus marking that cell as full if the object is not null. Send null to &#8217;empty&#8217; the cell.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Checks the first cell if cell size is 1. \nGridSquare myGrid;\n\nvoid Start()\n{\n    if(myGrid.CheckCellStatus(new Vector3(0.5f, 0, 0.5f)))\n    {\n        Debug.Log(&quot;This cell is empty&quot;);\n        \/\/The cell is empty, so you may now want to fill it.\n        myGrid.ChangeCellStatus(new Vector3(0.5f, 0, 0.5f), myObject);\n    }\n    else \n    {\n        Debug.Log(&quot;This cell is full&quot;);\n        \/\/This cell is full, so you may now want to empty it.\n        \/\/Send null in the arguements to &#39;empty&#39; the cell. \n        myGrid.ChangeCellStatus(new Vector3(0.5f, 0, 0.5f), null);\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public GameObject GetGridObjContainer()<\/strong><\/strong><\/h2>\n\n\n\n<p>Will return this grids container of objects that have been placed. The container is created at runtime.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Hides the game objects placed on the grid at start.\nGridSquare myGrid;\n\nvoid Start() \n{\n    myGrid.GetGridObjContainer.SetActive(false);\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public float GetCellSize()<\/strong><\/strong><\/h2>\n\n\n\n<p>Returns this grids cell size.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Debugs the grids cell size.\nGridSquare myGrid;\n\nvoid Start() \n{\n    Debug.Log(myGrid.GetCellSize());\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public float GetGridHeight()<\/strong><\/strong><\/h2>\n\n\n\n<p>Returns this grids grid height.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Debugs the grids height.\nGridSquare myGrid;\n\nvoid Start() \n{\n    Debug.Log(myGrid.GetGridHeight());\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public float GetGridWidth()<\/strong><\/strong><\/h2>\n\n\n\n<p>Returns this grids grid Width.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Debugs the grids width.\nGridSquare myGrid;\n\nvoid Start() \n{\n    Debug.Log(myGrid.GetGridWidth());\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:22px\"><strong><strong>public Dictionary&lt;Vector3, GameObject&gt; GetCellsDictionary()<\/strong><\/strong><\/h2>\n\n\n\n<p>Returns this grids Dictionary. There is a debug.log for each entry in the dictionary. This is sometimes useful for debugging purposes to actually see what each cell contains and if it matches the physical grid. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-csharp\" data-lang=\"C#\"><code>\/\/Debugs the grids Dictionary of cells.\n\/\/Each cell will have an entry of either the object placed, or null.\nGridSquare myGrid;\n\nvoid Start() \n{\n    myGrid.GetCellsDictionary();\n}<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>public bool CheckCellStatus(Vector3 cellPos) This function returns true if the given key (cellPos) is found in the dictionary and that position&#8217;s value is null. It will return false if that keys value is any object except for null. If the value is null, it means the cell is marked as empty, if it is anything [&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-1456","docs","type-docs","status-publish","hentry","doc_category-scripting"],"acf":[],"aioseo_notices":[],"year_month":"2026-04","word_count":442,"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\/1456","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=1456"}],"version-history":[{"count":16,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1456\/revisions"}],"predecessor-version":[{"id":1515,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/docs\/1456\/revisions\/1515"}],"wp:attachment":[{"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/media?parent=1456"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_category?post=1456"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/golemitegames.com\/index.php\/wp-json\/wp\/v2\/doc_tag?post=1456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}