evelynshilosky

EquipableItem - Part 31

Feb 1st, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 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.     //private 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.  
  45.     public void GetHit()
  46.     {
  47.         GameObject selectedTree = SelectionManager.Instance.selectedTree;
  48.  
  49.         if (selectedTree != null)
  50.         {
  51.             SoundManager.Instance.PlaySound(SoundManager.Instance.treeChopSound); //changed audio for personal preference
  52.  
  53.             selectedTree.GetComponent<ChoppableTree>().GetHit();
  54.         }
  55.     }
  56.    
  57.     IEnumerator SwingSoundDelay()
  58.     {
  59.         yield return new WaitForSeconds(0.45f); //changed time due to my audio clip
  60.         SoundManager.Instance.PlaySound(SoundManager.Instance.toolSwingSound);
  61.     }
  62.    
  63.  
  64. }
  65.  
Add Comment
Please, Sign In to add comment