The following script is not optimized. Review the script to see what can be done to optimize it. Then, review the information provided after the script:
public class CucumberManager : MonoBehavior { public static int currentCucumberCount; Text Cucumber_Count; public GameObject[] cucumbers; void Update() { Cucumber_Count = GetComponent<Text>(); currentCucumberCount = 1; cucumbers = GameObject.FindGameObjectsWithTag("Cucumber"); Cucumber_Count.text = cucumbers.Length.ToString(); currentCucumberCount = cucumbers.Length; }}
Hopefully you were able to spot the inefficient, unoptimized component of the script. In the preceding example, all the statements other than the variable declarations occur in the Update() method. Consider ...