Esempio n. 1
0
    //go and activate

    /*IEnumerator WaitAndGather(Vector3 targetpos)
     * {
     *  float timeToReach = (_playerMovement.CalculatePathLength(targetpos)) / (_playerNavMeshAgent.speed);
     *  yield return new WaitForSeconds(timeToReach);
     *  Collider[] hitColliders = Physics.OverlapSphere(_player.transform.position, 3f);
     *  bool isNearObject = false;
     *  foreach (var collider in hitColliders)
     *  {
     *      if (collider == resource.GetComponent<Collider>())
     *      {
     *          isNearObject = true;
     *      }
     *  }
     *
     *  if (_playerMovement.IsPathCompleted() & isNearObject)
     *  {
     *      Gather();
     *  }
     * }*/

    private void Gather()
    {
        _animator.SetTrigger("chop");
        _playerResources.AddResource(resourceID, toolEfficiency);
        resourceQuantity -= toolEfficiency;
        _playerExperience.AddExp(ExpID, Convert.ToUInt64(toolEfficiency));
        var popup = Instantiate(resourcePopup, transform.position, Quaternion.identity);

        popup.GetComponent <ResourcePopup>().SetText(toolEfficiency);
        popup.GetComponent <ResourcePopup>().SetIcon(icon);
        if (resourceQuantity <= 0)
        {
            audioManager.Play(GenerateSoundName(true, 1));
            resource.SetActive(false);
            depletedResource.SetActive(true);
            _playerNavMeshAgent.ResetPath();
            StartRespawn();
        }
        else
        {
            audioManager.Play(GenerateSoundName(false, 3));
        }
    }
Esempio n. 2
0
 private void Gather()
 {
     if (!isDepleted)
     {
         int toolEff = _playerEq.toolEfficiency;
         _animator.SetTrigger("chop");
         int gatherValue;
         int tmp = resourceQuantity - toolEff;
         if (tmp >= 0)
         {
             gatherValue = toolEff;
         }
         else
         {
             gatherValue = toolEff + tmp;
         }
         _playerResources.AddResource(resourceID, gatherValue);
         resourceQuantity -= gatherValue;
         _playerExperience.AddExp(ExpID, Convert.ToUInt64(gatherValue));
         var popup = Instantiate(resourcePopup);
         popup.GetComponent <ResourcePopup>().SetText(gatherValue);
         popup.GetComponent <ResourcePopup>().SetIcon(icon);
         if (resourceQuantity <= 0)
         {
             audioManager.Play(GenerateSoundName(true, 1));
             resource.SetActive(false);
             depletedResource.SetActive(true);
             meshCollider.isTrigger = true;
             StartRespawn();
             isDepleted = true;
         }
         else
         {
             audioManager.Play(GenerateSoundName(false, 3));
         }
     }
 }