public string detectGarbage(Vector2 truckGridPosition) { string action = "noChange"; //Checking if garbage can be picked by the truck matchAngles(); foreach (GarbageElement garbageIterator in garbageObjectArray) { Vector2Int garbageElementGridPosition = v3tov2int(garbageIterator.garbageElement.transform.position); Vector2Int dustbin1GridPosition = v3tov2int(dustbin1.transform.position); Vector2Int dustbin2GridPosition = v3tov2int(dustbin2.transform.position); if ((truckGridPosition - garbageElementGridPosition).magnitude < Constants.pickupDistance) { garbageObjectArray.Remove(garbageIterator); if (!truck.isPopUpSet && truck.currentClassifyPower <= 0) { action = truck.Classify(garbageIterator.isBiodegradable, garbageIterator.garbageElement.GetComponent <SpriteRenderer>().sprite, garbageIterator.garbageName); //Add Clasification } else if (!truck.isPopUpSet && truck.currentClassifyPower > 0) { action = "increaseCorrectGarbage"; } else { action = "noChange"; } Object.Destroy(garbageIterator.garbageElement); Object.Destroy(garbageIterator.miniGarbage); break; } if ((truckGridPosition - dustbin1GridPosition).magnitude < Constants.dropDistance) { action = "empty"; SpawnDisposal(dustbin1GridPosition); } if ((truckGridPosition - dustbin2GridPosition).magnitude < Constants.dropDistance) { action = "empty"; SpawnDisposal(dustbin2GridPosition); } } return(action); }