using System; using Unity.Mathematics; using UnityEngine; using Random = UnityEngine.Random; using AK.Wwise; // Make sure your Wwise namespace is correct public class BushInteraction : MonoBehaviour { [SerializeField] private int blueberryCount; #if UNITY_EDITOR void OnValidate() { if (blueberryCount > 0) { // If the UID is already set, we don't need to do anything return; } // Generate a new UID based on the position of the object blueberryCount = Random.Range(1, 5); } #endif [SerializeField] private GameObject emptyBush; private bool BlueBerriesPicked = false; // Wwise Events public AK.Wwise.Event PlayBushesEvent; public AK.Wwise.Event PlayBerryWithBushEvent; void Start() { } void OnTriggerEnter(Collider other) { if (!BlueBerriesPicked) { if (emptyBush == null) { PlayBushesEvent.Post(gameObject); return; } if (other.CompareTag("Player")) { // Play the "Play_BerryWithBush" event if bush has berries PlayBerryWithBushEvent.Post(gameObject); other.gameObject.GetComponent().CollectBlueberry(blueberryCount); ChangeBushAppearance(); blueberryCount = 0; BlueBerriesPicked = true; } } } public int GetBlueberryCount() { return blueberryCount; } public void SetBlueberryCount(int count) { blueberryCount = count; if (blueberryCount == 0 && BlueBerriesPicked) { ChangeBushAppearance(); } } public void ChangeBushAppearance() { Vector3 currentPosition = transform.position; Quaternion currentRotation = transform.rotation; Transform parent = transform.parent; Destroy(gameObject); GameObject _emptyBush = Instantiate(emptyBush, currentPosition, currentRotation); } public void SetBlueberriesPicked(bool picked) { BlueBerriesPicked = picked; } public bool AreBlueberriesPicked() { return BlueBerriesPicked; } }