The Swarm class contains three variables:
- droneCount: This is an integer referencing the number of Swarm class members that have been created.
- dronePrefab: This references the prefab to be cloned to create swarm members.
- drones: This is a list of objects that reference drones; a list of all the scripted Drone components inside all the Swarm objects that have been created.
Upon creation, as the scene starts, the Swarm script class's Awake() method loops to create droneCount swarm members by repeatedly calling the AddDrone() method. This method instantiates a new GameObject from the prefab and then sets the newDrone variable to be a reference to the Drone scripted object inside the new Swarm class member. In each frame, the FixedUpdate() method loops through the list of Drone objects by calling their SetTargetPosition(...) method, and passes in the Swarm center's location and the average of all the swarm member's velocities.
The rest of this Swarm...