Question by
JanZagar · Jun 27, 2017 at 11:44 AM ·
audiosourcetagaudiocliponcollisionenterplayoneshot
I'm trying to play a sound OnCollisionEnter, but something isn't working right. Can you help me ?
So this is the code:
AudioSource sound;
public AudioClip impact;
void Start () {
sound = GetComponent<AudioSource> ();
}
void OnCollisionEnter(Collision other) {
if (other.gameObject.tag=="ball") {
Debug.Log ("Play the impact sound");
sound.PlayOneShot (impact);
}
hitPoints--;
if (hitPoints <= 0) {
Die ();
}
}
and the code doesn't work even if I don't ask for the tag "ball", but if i put sound.PlayOneShot (impact); in void Start() the sound does play. Idk what is wrong.
Please help.
Comment