private void OnTriggerEnter(Collider other) { switch (antState) { case AntState.CollectingSugar: Sugar sugar = other.gameObject.GetComponent <Sugar>(); if (seek.target != null && sugar != null) { if (sugar.gameObject == seek.target.gameObject) { sugar.GetEaten(); SugarCollected++; if (SugarCollected == SugarToCollect) { antState = AntState.GoingToColony; seek.target = colonyTransform; } else { sugar = sugarController.GetRandomSugar(); if (sugar != null) { seek.target = sugar.transform; } else { antState = AntState.GoingToColony; seek.target = colonyTransform; } } } } break; } }
void CollectSugar() { // state update if (null != sugar) { if (Vector3.Distance(sugar.transform.position, transform.position) < 0.5) { sugar.GetEaten(); SugarCollected++; if (SugarCollected == SugarToCollect) { activeState = GoToColony; seek.target = colonyTransform; } else { sugar = sugarController.GetRandomSugar(); if (null != sugar) { seek.target = sugar.transform; } else { activeState = GoToColony; seek.target = colonyTransform; } } } } }
private void OnTriggerEnter(Collider other) { Sugar sugar = other.gameObject.GetComponent <Sugar>(); if (seek.target != null && sugar != null) { if (sugar.gameObject == seek.target.gameObject) { if (!sugar.IsCollected) { sugar.GetEaten(); SugarHit = true; } } } }