51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
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 GameObject emptyBush;
|
|
|
|
private int blueberryCount = 0;
|
|
private bool BlueBerriesPicked = false;
|
|
|
|
// Wwise Events
|
|
public AK.Wwise.Event PlayBushesEvent;
|
|
public AK.Wwise.Event PlayBerryWithBushEvent;
|
|
|
|
void Start()
|
|
{
|
|
blueberryCount = Random.Range(1, 5); // Randomly initialize blueberry count between 1 and 5
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!BlueBerriesPicked)
|
|
{
|
|
if (emptyBush == null)
|
|
{
|
|
PlayBushesEvent.Post(gameObject);
|
|
return;
|
|
}
|
|
// Play the "Play_BerryWithBush" event if bush has berries
|
|
PlayBerryWithBushEvent.Post(gameObject);
|
|
|
|
other.gameObject.GetComponent<PlayerInteraction>().CollectBlueberry(blueberryCount);
|
|
|
|
Vector3 currentPosition = transform.position;
|
|
Quaternion currentRotation = transform.rotation;
|
|
Transform parent = transform.parent;
|
|
|
|
Destroy(gameObject);
|
|
|
|
GameObject _emptyBush = Instantiate(emptyBush, currentPosition, currentRotation);
|
|
// Optionally assign parent if needed
|
|
// _emptyBush.transform.parent = parent;
|
|
|
|
BlueBerriesPicked = true;
|
|
}
|
|
|
|
}
|
|
} |