Advertisement
evelynshilosky

EquipableItem - Part 32

Feb 12th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(Animator))]
  6. public class EquipableItem : MonoBehaviour
  7. {
  8.  
  9.     public Animator animator;
  10.     public bool swingWait = false;
  11.  
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         animator = GetComponent<Animator>();
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.  
  23.         if (Input.GetMouseButtonDown(0) && // Left Mouse Button
  24.             InventorySystem.Instance.isOpen == false &&
  25.             CraftingSystem.Instance.isOpen == false &&
  26.             SelectionManager.Instance.handIsVisible == false &&
  27.             swingWait == false &&
  28.             !ConstructionManager.Instance.inConstructionMode
  29.             )
  30.         {
  31.             // wait for the swing to complete, before allowing another swing
  32.             swingWait = true;
  33.  
  34.             StartCoroutine(SwingSoundDelay());
  35.  
  36.             animator.SetTrigger("hit");
  37.  
  38.             StartCoroutine(NewSwingDelay());
  39.         }
  40.     }
  41.  
  42.  
  43.  
  44.     public void GetHit()
  45.     {
  46.         GameObject selectedTree = SelectionManager.Instance.selectedTree;
  47.  
  48.         if (selectedTree != null)
  49.         {
  50.             SoundManager.Instance.PlaySound(SoundManager.Instance.treeChopSound); //changed audio for personal preference
  51.  
  52.             selectedTree.GetComponent<ChoppableTree>().GetHit();
  53.         }
  54.     }
  55.    
  56.     IEnumerator SwingSoundDelay()
  57.     {
  58.         yield return new WaitForSeconds(0.45f); //changed time due to my audio clip
  59.         SoundManager.Instance.PlaySound(SoundManager.Instance.toolSwingSound);
  60.     }
  61.  
  62.  
  63.     IEnumerator NewSwingDelay()
  64.     {
  65.         yield return new WaitForSeconds(1f); // This delay is hardcoded for the axe
  66.         swingWait = false;
  67.     }
  68.  
  69.  
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement