March 2018
Beginner
336 pages
8h 6m
English
As you might imagine, the script for counting beetles will be very similar to the method we used for counting cucumbers. This time, we will add a BeetleManager script to our Beetle_Count UI component. Here is the required script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class BeetleManager : MonoBehaviour { public int currentBeetleCount; Text Beetle_Count; public GameObject[] beetles; void Awake () { Beetle_Count = GetComponent<Text> (); currentBeetleCount = 0; } void Update () { beetles = GameObject.FindGameObjectsWithTag ("Beetle"); Beetle_Count.text = beetles.Length.ToString(); } }
This code is very similar to our CucumberManager ...
Read now
Unlock full access