// Update is called once per frame void Update() { switch (state) { default: case State.idle: break; case State.gathering: if (!moving && !moveai.arrived) { if (goldDest == null) { NodeTracker t = sys.GetComponent <NodeTracker>(); List <GameObject> goldNodes = t.goldNodes; goldDest = NodeTracker.closestObject(goldNodes, this.transform); goldnode = goldDest.GetComponent <GoldNode>(); } Vector3 goldGather = goldnode.gatherPoint; moveTo(goldGather); } if (moveai.arrived) { moving = false; if (!Mrunning) { StartCoroutine(mining()); } if (worker.carrying >= worker.capacity) { moveai.arrived = false; state = State.depositing; } } break; case State.depositing: if (!moving && !moveai.arrived) { moveTo(depotDest); } if (moveai.arrived) { moving = false; if (!Drunning) { StartCoroutine(depositing()); } } if (worker.carrying == 0) { moveai.arrived = false; state = State.gathering; } break; } }