✨ altered BushInteraction.cs
This commit is contained in:
parent
ae9fd8a087
commit
4464383a4d
@ -6,9 +6,22 @@ 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 int blueberryCount = 0;
|
||||
private bool BlueBerriesPicked = false;
|
||||
|
||||
// Wwise Events
|
||||
@ -17,7 +30,6 @@ public class BushInteraction : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
blueberryCount = Random.Range(1, 5); // Randomly initialize blueberry count between 1 and 5
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
@ -33,19 +45,42 @@ public class BushInteraction : MonoBehaviour
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user