altered BushInteraction.cs

This commit is contained in:
AgentSchmisch 2025-06-17 14:25:18 +02:00
parent ae9fd8a087
commit 4464383a4d

View File

@ -6,9 +6,22 @@ using AK.Wwise; // Make sure your Wwise namespace is correct
public class BushInteraction : MonoBehaviour 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; [SerializeField] private GameObject emptyBush;
private int blueberryCount = 0;
private bool BlueBerriesPicked = false; private bool BlueBerriesPicked = false;
// Wwise Events // Wwise Events
@ -17,7 +30,6 @@ public class BushInteraction : MonoBehaviour
void Start() void Start()
{ {
blueberryCount = Random.Range(1, 5); // Randomly initialize blueberry count between 1 and 5
} }
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
@ -33,7 +45,26 @@ public class BushInteraction : MonoBehaviour
PlayBerryWithBushEvent.Post(gameObject); PlayBerryWithBushEvent.Post(gameObject);
other.gameObject.GetComponent<PlayerInteraction>().CollectBlueberry(blueberryCount); other.gameObject.GetComponent<PlayerInteraction>().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; Vector3 currentPosition = transform.position;
Quaternion currentRotation = transform.rotation; Quaternion currentRotation = transform.rotation;
Transform parent = transform.parent; Transform parent = transform.parent;
@ -41,11 +72,15 @@ public class BushInteraction : MonoBehaviour
Destroy(gameObject); Destroy(gameObject);
GameObject _emptyBush = Instantiate(emptyBush, currentPosition, currentRotation); GameObject _emptyBush = Instantiate(emptyBush, currentPosition, currentRotation);
// Optionally assign parent if needed
// _emptyBush.transform.parent = parent;
BlueBerriesPicked = true;
} }
public void SetBlueberriesPicked(bool picked)
{
BlueBerriesPicked = picked;
}
public bool AreBlueberriesPicked()
{
return BlueBerriesPicked;
} }
} }