{"id":117,"date":"2010-09-14T18:17:41","date_gmt":"2010-09-15T01:17:41","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=117"},"modified":"2010-09-14T18:22:00","modified_gmt":"2010-09-15T01:22:00","slug":"lab-8-arrays","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2010\/09\/lab-8-arrays\/","title":{"rendered":"Lab 8 &#8211; Arrays"},"content":{"rendered":"<p>This week&#8217;s lab involves experimenting with arrays.<\/p>\n<p>Start with the following behaviour:<\/p>\n<p><code><br \/>\n\/\/ Flowers.js<br \/>\nvar flowerPrefab : GameObject;<br \/>\nvar heights : float[];<br \/>\nvar flowers : GameObject[];<\/code><br \/>\n<code><br \/>\nfunction Start() {<br \/>\n   \/\/ make as many instances of the prefab<br \/>\n   \/\/ as there are entries in the 'heights' array<br \/>\n   \/\/ scale each one according to the height<br \/>\n   \/\/ store them in the flowers[] array<br \/>\n}<\/code><br \/>\n<code><br \/>\nfunction Update() {<br \/>\n   \/\/ Find the smallest flower and make it grow a little<br \/>\n}<br \/>\n<\/code><\/p>\n<p><strong>Task 1:<\/strong> Complete the <code>Start()<\/code> method so that it creates multiple instances of the prefab with the specified heights. Make them stand in a line (or, if you&#8217;re more adventurous, a circle). Add the script to an empty object (lets call it the flowerbed) in the world and test it out with different values of the heights array.<\/p>\n<p>Store a reference to each flower you make in the <code>flowers<\/code> array, so we can access them in <code>Update().<\/code><\/p>\n<p><strong>Task 2:<\/strong> Complete the <code>Update()<\/code> method so that on each frame the whichever flower is currently smallest and make it grow a little.<\/p>\n<p>To do this, you will need to use a for loop to look at all the flowers in the <code>flowers<\/code> array and check its height against the smallest you have found so far.<\/p>\n<p>Test your code with different numbers of flowers. Does it work with 10? 100? 1? 0?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week&#8217;s lab involves experimenting with arrays. Start with the following behaviour: \/\/ Flowers.js var flowerPrefab : GameObject; var heights : float[]; var flowers : GameObject[]; function Start() { \/\/ make as many instances of the prefab \/\/ as there are entries in the &#8216;heights&#8217; array \/\/ scale each one according to the height \/\/ [&hellip;]<\/p>\n","protected":false},"author":80,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/users\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":8,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":120,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/117\/revisions\/120"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}