Exemple #1
0
    private IEnumerator MoveToResource(ResourceNode node)
    {
        NavMeshObstacle obstacle = node.GetComponent <NavMeshObstacle>();
        float           distance = Vector3.Distance(transform.position, node.transform.position);
        Vector3         movePos  = Vector3.Lerp(transform.position, node.transform.position,
                                                (distance - obstacle.radius - _playerMovement.NavAgent.radius - 1.5f) / distance);

        _playerMovement.SetDestination(movePos);
        _playerMovement.sphere.position = movePos;

        while (Vector3.Distance(transform.position, movePos) > 0.5f)
        {
            yield return(null);
        }
        KeyValuePair <Resource, int> harvest = node.Harvest();

        if (InventoryManager.Instance.Resources.ContainsKey(harvest.Key))
        {
            InventoryManager.Instance.Resources[harvest.Key] += harvest.Value;
        }
        else
        {
            InventoryManager.Instance.Resources.Add(harvest.Key, harvest.Value);
        }
        Debug.Log("You have " + InventoryManager.Instance.Resources[harvest.Key] + " " + harvest.Key.ToString());
    }
Exemple #2
0
 private void ProcessInputEvents()
 {
     if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
     {
         if (Input.GetMouseButtonDown(0))
         {
             PlayerActions.DoAction();
         }
         if (Input.GetMouseButton(1))
         {
             PlayerMovement.SetDestination();
         }
     }
 }