using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; public class TreeFallTrigger : MonoBehaviour { AudioSource source; Animation anim; bool fell = false; private void Awake() { source = GetComponent(); anim = GetComponent(); if (!anim) anim = GetComponentInParent(); } private void OnTriggerEnter(Collider other) { if (Random.Range(0, 100) < 50) return; if (other.CompareTag("Player") && !fell) { fell = true; if (!anim || !source) return; anim.Play("fall"); source.Play(); } } }