public bool Gather(UnitController cont, GameObject obj) { if (manager == null) { manager = GameObject.Find("Player Manager").GetComponent <ResourceManager>(); } if (resourceUnit) { if (source != null) { sourceIndex = source.resourceIndex; if (behaviour[sourceIndex].canGather) { if (behaviour[sourceIndex].lastGather + behaviour[sourceIndex].rate < Time.time) { int amount = 0; behaviour[sourceIndex].lastGather = Time.time; if (behaviour[sourceIndex].returnWhenFull) { int drainAmount = 0; if (drainAmount <= behaviour[sourceIndex].carryCapacity - behaviour[sourceIndex].carrying) { drainAmount = behaviour[sourceIndex].amount; } else { drainAmount = behaviour[sourceIndex].carryCapacity - behaviour[sourceIndex].carrying; } amount = source.RequestResource(drainAmount); if (nearestDropOff == null) { FindNearestDropOff(obj); } behaviour[sourceIndex].carrying += amount; if (source == null || behaviour[sourceIndex].carrying >= behaviour[sourceIndex].carryCapacity) { ReturnToDropOff(cont); } } else { amount = source.RequestResource(behaviour[sourceIndex].amount); manager.resourceTypes[sourceIndex].amount += amount; } if (amount > 0) { return(true); } else { return(false); } } else { return(true); } } else { return(false); } } else { return(false); } } else { return(false); } }