36 lines
631 B
C#
36 lines
631 B
C#
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<AudioSource>();
|
|
anim = GetComponent<Animation>();
|
|
if (!anim)
|
|
anim = GetComponentInParent<Animation>();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
} |