COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Lab 8 – Arrays

Posted by on September 14th, 2010 · Lab

This week’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 'heights' array
// scale each one according to the height
// store them in the flowers[] array
}


function Update() {
// Find the smallest flower and make it grow a little
}

Task 1: Complete the Start() method so that it creates multiple instances of the prefab with the specified heights. Make them stand in a line (or, if you’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.

Store a reference to each flower you make in the flowers array, so we can access them in Update().

Task 2: Complete the Update() method so that on each frame the whichever flower is currently smallest and make it grow a little.

To do this, you will need to use a for loop to look at all the flowers in the flowers array and check its height against the smallest you have found so far.

Test your code with different numbers of flowers. Does it work with 10? 100? 1? 0?

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.