Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(BoxCollider))]
- public class ChoppableTree : MonoBehaviour
- {
- public bool playerInRange;
- public bool canBeChopped;
- public float treeMaxHealth;
- public float treeHealth;
- private void Start()
- {
- treeHealth = treeMaxHealth;
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInRange = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInRange = false;
- }
- }
- public void GetHit()
- {
- StartCoroutine(hit());
- }
- public IEnumerator hit()
- {
- yield return new WaitForSeconds(0.6f);
- treeHealth -= 1;
- }
- private void Update()
- {
- if (canBeChopped)
- {
- GlobalState.Instance.resourceHealth = treeHealth;
- GlobalState.Instance.resourceMaxHealth = treeMaxHealth;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement