- Home /
Question by
GameDevH2O · Jul 07, 2018 at 01:33 AM ·
c#2daudio
Sound effect issue
Hello I have a sound effect working perfectly for the main player because a tutorial I just watched but I tried to do the same thing for an enemy & it does not work I put the sound to play under OnTriggerEnter2D idk what’s wrong
public AudioSource Sound;
void Start ()
{
Player = GetObject.Find(“Player”);
Sound = GetComponent<AudioSource>();
}
void OnTriggerEnter2D(Collider2D col)
{
if ((col.tag == “Player” || (col.tag == “Bullet”))
{
Sound.Play ();
Destroy(GameObject);
}
Comment
Answer by Priyanka-Rajwanshi · Jul 07, 2018 at 09:24 AM
There is no pre-defined function name Player in the class AudioSource. It should be
Sound.Play();
Sorry bout that auto correct put player but it is Sound.Play();
& it doesn’t play in game view
Your answer
![](https://koobas.hobune.stream/wayback/20220612170209im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Audio Trigger 3 Answers
How To Make An Invisible Wall That's Impossible To Get Out Of? 1 Answer
Every few seconds, play an audio clip 3 Answers