using System; using Unity.Mathematics; using UnityEngine; using Random = UnityEngine.Random; public class BushInteraction : MonoBehaviour { [SerializeField] private GameObject emptyBush; private int blueberryCount = 0; private bool BlueBerriesPicked = false; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { blueberryCount = Random.Range(1, 5); // Randomly initialize blueberry count between 1 and 5 } // Update is called once per frame void Update() { } void OnTriggerEnter(Collider other) { // increase blueberry count in the Inventory if (!BlueBerriesPicked) { other.gameObject.GetComponent().CollectBlueberry(blueberryCount); // switch to different bush model, so that the player can see that the bush is empty Vector3 currentPosition = transform.position; Quaternion currentRotation = transform.rotation; Transform parent = transform.parent; // kill the bush with blueberries Destroy(gameObject); GameObject _emptyBush = Instantiate(emptyBush, currentPosition, currentRotation); //_emptyBush.transform.parent = parent; BlueBerriesPicked = true; } } }