I tried to search button and it gives me a 504 error… I’ve googled this, and checked multiple pages but I’m just not understanding it.
I have an enemy object, that when its health is at or below 0, it blows up, and creates an explosion prefab that plays an explosion sound… that works fine. I attached an audio file called “ricochet” to the enemy object thru the variable
var soundRicochet : AudioClip;
So. I then have the enemy have health, and each bullet lowers it’s health, and if it’s health is not zero or less, it’s supposed to play the ricochet sound. It doesn’t play the audio file, and gives me a “there is no audio source attached to the object…” I’ve read multiple things on google, and people are saying stuff like you gotta put
@script RequireComponent (AudioSource)
I try it but maybe I’m putting it in the wrong spot. Here’s my code.
var soundRicochet : AudioClip;
.
.
.
function OnTriggerEnter( otherObject: Collider) // collision with bullet, lowers health
{
if (otherObject.gameObject.tag == "bullet")
{
playerScript.playerScore += 100;
enemyHealth -= 1;
if (enemyHealth >= 1)
{
audio.PlayOneShot(soundRicochet);
}
}
}
so as you can see, if the enemy still has health after being hit, it should play the ricochet sound so you know it hit the enemy. What am I doing wrong? Thanks in advance!
EDIT: Also, I have dragged and dropped the ricochet.wav from the project tab to the “soundRicochet” spot in the inspector area.