protected void OnTriggerEnter2D(Collider2D collision) { if (currentTask == TaskTypes.Joy) { JoyZone zoneJoy = collision.GetComponent <JoyZone>(); if (zoneJoy != null) { if (zoneJoy.areaFull) { fullJoyZones.Add(zoneJoy); Transform newPos = FindJoyLocation(); SetTarget(newPos); } } } if (currentTask == TaskTypes.Social) { InteractionZone zoneInteraction = collision.GetComponent <InteractionZone>(); if (zoneInteraction != null) { if (zoneInteraction.areaFull) { fullInteractionZones.Add(zoneInteraction); Transform newPos = FindInteractionLocation(); SetTarget(newPos); } } } }
protected Transform FindJoyLocation() { JoyZone[] joyZones = FindObjectsOfType <JoyZone>(); JoyZone currentClosest = null; float distToClosest = Mathf.Infinity; foreach (JoyZone zone in joyZones) { if (!fullJoyZones.Contains(zone)) { float newDist = (zone.transform.position - transform.position).sqrMagnitude; if (newDist < distToClosest) { distToClosest = newDist; currentClosest = zone; } } } return(currentClosest.transform); }