Advertisement
evelynshilosky

ChoppableTree - Part 14

Jun 6th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(BoxCollider))]
  6. public class ChoppableTree : MonoBehaviour
  7. {
  8.    
  9.     public bool playerInRange;
  10.     public bool canBeChopped;
  11.  
  12.     public float treeMaxHealth;
  13.     public float treeHealth;
  14.  
  15.  
  16.  
  17.     private void Start()
  18.     {
  19.         treeHealth = treeMaxHealth;
  20.     }
  21.  
  22.  
  23.     private void OnTriggerEnter(Collider other)
  24.     {
  25.         if (other.CompareTag("Player"))
  26.         {
  27.             playerInRange = true;
  28.         }
  29.     }
  30.  
  31.  
  32.  
  33.  
  34.     private void OnTriggerExit(Collider other)
  35.     {
  36.         if (other.CompareTag("Player"))
  37.         {
  38.             playerInRange = false;
  39.         }
  40.     }
  41.  
  42.  
  43.     public void GetHit()
  44.     {
  45.         StartCoroutine(hit());
  46.     }
  47.  
  48.     public IEnumerator hit()
  49.     {
  50.         yield return new WaitForSeconds(0.6f);
  51.         treeHealth -= 1;
  52.     }
  53.  
  54.  
  55.  
  56.     private void Update()
  57.     {
  58.         if (canBeChopped)
  59.         {
  60.             GlobalState.Instance.resourceHealth = treeHealth;
  61.             GlobalState.Instance.resourceMaxHealth = treeMaxHealth;
  62.         }
  63.     }
  64.  
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement