//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)); } }
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)); } } }
private void Update() { if (player1 != null && player1CanGather == true && Input.GetButtonDown("GatherPlayer1")) { if (resourceAmount == 0) { player1CanGather = false; return; } resourceAmount--; AudioManager.PlaySound(soundToPlay); player1ResourcesScript.AddResource(1, id); StartCoroutine(GatheringTime(0)); } else if (player2 != null && player2CanGather == true && Input.GetButtonDown("GatherPlayer2")) { if (resourceAmount == 0) { player2CanGather = false; return; } resourceAmount--; AudioManager.PlaySound(soundToPlay); player2ResourcesScript.AddResource(1, id); StartCoroutine(GatheringTime(1)); } if (resourceAmount == MaxResourceAmount / 2 - MaxResourceAmount % 2 || resourceAmount == 0) { ChangeSprite(); } }
private void ProcessInput() { //Left if (Input.GetMouseButtonDown(0) || Input.GetButtonDown("Destruct")) { if (DialogueManager.Instance.IsInDialogue) { m_CurrentDialogue.NextDialogue(); } else if (m_CurrentInteractable != null) { if (m_CurrentInteractable.InteractableType == EInteractableType.Dialogue) { m_CurrentDialogue = m_CurrentInteractable.GetComponent <DialogueInteractable>(); if (m_CurrentDialogue == null) { Debug.LogError("No DialogueInteractable component found"); } else { m_CurrentDialogue.StartDialogue(EndDialogue); } } else { m_CurrentInteractType = EInteractType.Destruct; if (m_CurrentInteractable.InteractableType == EInteractableType.Destructable) { m_PlayerResources.AddResource(m_CurrentInteractable.ResourceType, m_CurrentInteractable.ResourceValue); m_CurrentInteractable.StartDestruct(); } if (PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.IdleLeft || PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.MovingLeft) { PlayerDataModule.Inst.playerMovement.playerState = PlayerMovement.PlayerState.DestructLeft; } if (PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.IdleRight || PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.MovingRight) { PlayerDataModule.Inst.playerMovement.playerState = PlayerMovement.PlayerState.DestructRight; } } } } //Right if (Input.GetMouseButtonDown(1) || Input.GetButtonDown("Repair")) { m_CurrentInteractType = EInteractType.Repair; if (m_CurrentInteractable != null && m_CurrentInteractable.InteractableType == EInteractableType.Repairable && m_PlayerResources.resources[(int)m_CurrentInteractable.ResourceType].Count > 0) { m_PlayerResources.UseResource(m_CurrentInteractable.ResourceType, m_CurrentInteractable.ResourceValue); m_CurrentInteractable.StartRepair(); } if (PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.IdleLeft || PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.MovingLeft) { PlayerDataModule.Inst.playerMovement.playerState = PlayerMovement.PlayerState.RepairLeft; } if (PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.IdleRight || PlayerDataModule.Inst.playerMovement.playerState == PlayerMovement.PlayerState.MovingRight) { PlayerDataModule.Inst.playerMovement.playerState = PlayerMovement.PlayerState.RepairRight; } } }