How To Play Audio Every 3-4 Times

I have this script here, and right now it’s set to where every time you see theEnemy it plays every time. i’d like it to play every 3rd or fourth time and i don’t know where to start.

I would address this with a simple function counter that keeps track of how many times the enemy has been seen and use that to determine if the sound needs to be played. Here is a snippet that demonstrates the idea.

private var enemySeenCount : int = 0;
private var enemySeenThreshold : int = 4;

// Check if the enemy has been seen
// more than the threshold
if(enemySeenCount > enemySeenThreshold)
{
  // Reset our count if we surpassed
  // the threshold
  enemySeenCount = 0;
}

else
{
  // Otherwise, we simply increment the
  // count of how many times the enemy
  // was spotted
  enemySeenCount++;
}

// Play sound if we are at the
// beginning of our count
if(enemySeenCount == 0)
{
  audio.PlayClipAtPoint( enemySightedSFX, thePlayer.position );
}

I know my example, doesn’t fit in your code at present. However, it should give you a nice place to start to use incremental counters.