Game Development Reference
In-Depth Information
4.
Save the script, and click Play to see the results (Figure 7-38 ).
Figure 7-38. The randomized veggies
The plants a looking pretty good. But there's one more thing you could do to them. Given the
number of marauding zombie bunnies devouring the garden, you'd expect to see lots of plants
missing. So the final refinement will be to remove random plants, or better yet, prevent them from
being instantiated. To do that, you will wrap all of the Instantiation and customization code in an if
statement. The condition will be a percent specified in the bed's set up. If the random number is less
than that percent, the plant is skipped over during planting.
1.
Add one more variable to the rest of the regular variables:
public int percent = 20; // percent of missing plants
Below the Vector3 pos = new Vector3 line, add
2.
int rPercent = Random.Range (1,101); // 1-100%
if (rPercent > percent) { // plant the plant
3.
Add the closing curly bracket below the randomize scale section, and indent
the contents of the new conditional.
4.
Save the script, and click Play to see the results.
The plants now look authentically decimated by the zombie bunnies (Figure 7-39 ).
Search WWH ::




Custom Search