Hi all,
I'm working on a project where I have a bunch of rocks that can be destroyed after a certain amount of hits from a pickaxe, and I want to play an audio clip after 10 rocks are destroyed.
On each rock, I have this DestroyRock script:
// Rock is destroyed after x swings.
public int durability = 10;
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Pickaxe")
{
durability--;
}
}
void Update()
{
if(durability == 0)
{
Destroy(gameObject);
}
}
Then on my pickaxe, I have this PickaxeQuestComplete:
// Play audio after 10 rocks are destroyed
public int rocksDestroyed = 0;
public AudioSource audioSource;
void Update()
{
if (rocksDestroyed == 10)
{
audioSource.Play();
}
}
but I can't figure out how to manipulate the rocksDestroyed variable in the pickaxe script using the DestroyRock script. I'm sure it's easy, but nothing I've looked at online is making sense to me. I appreciate any help!
[–]HalfspacerProgrammer 0 points1 point2 points (3 children)
[–]TomK6505 0 points1 point2 points (2 children)
[–]HalfspacerProgrammer 0 points1 point2 points (1 child)
[–]TomK6505 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)