예제 #1
0
        public void GatherResource(ResourceNode resource)
        {
            if (_isDead)
            {
                return;
            }
            if (!canGather)
            {
                return;
            }
            if (resource.Equals(GatheringTarget))
            {
                return;
            }
            if (GatheringTarget)
            {
                GatheringTarget.RemoveGatherer(teamId);
            }
            _enemyUnit      = null;
            _isGathering    = false;
            inResourceRange = false;

            // Get a Random point around the resource within the gathering radius
            // var vector2 = Random.insideUnitCircle.normalized * resource.gatherRadius;
            // var destination =  resource.transform.position + new Vector3(vector2.x, 0, vector2.y);
            var resourcePosition = resource.transform.position;
            var randomPosition   = Random.insideUnitCircle * resource.gatherRadius;
            var destination      = resourcePosition + new Vector3(randomPosition.x, 0, randomPosition.y);

            NavMesh.SamplePosition(destination, out var hit, 3f, NavMesh.AllAreas);
            GatheringTarget = resource;
            MoveTo(hit.position, false);
            _currentState = UnitState.Gathering;
        }