// Check the status of the action tracker and execute, cancel or update the current action protected void UpdateActionState() { if (actionTracker.ActionIsRunning()) { // if the action is running, update current progress if (IsCloseEnough(actionTracker.interactible)) { actionTracker.progress += Time.deltaTime; if (actionTracker.progress >= actionTracker.action.duration) { FinishAction(); } } else // if we are too far from the object, the current action is canceled { CancelAction(); } } else if (actionTracker.ActionWaitToBeExecuted() && IsCloseEnough(actionTracker.interactible)) { ExecuteAction(); } else { // do nothing } }
// Update is called once per frame void Update() { if (actionTraker.ActionIsRunning()) { Show(); progressBar.fillAmount = actionTraker.progress / actionTraker.action.duration; progressBar.transform.parent.transform.position = actionTraker.interactible.transform.position + Vector3.right * offsetX + Vector3.up * offsetY; } else { Hide(); } }