Hello,
I have a problem with the audio source that is not playing on trigger, however it is playing on awake just fine, I don’t know where is the problem
Here is my code:
public class FruitRotator2 : MonoBehaviour {
//public GameObject snakeObject;
public Transform particles;
private AudioSource audioSrc;
//score
public static int count;
// Use this for initialization
void Start () {
//initialize counter
count = 0;
//initialize audio source
audioSrc = gameObject.GetComponent<AudioSource>();
//stop particles
particles.GetComponent<ParticleSystem>().enableEmission = false;
}
// Update is called once per frame
void Update () {
transform.Rotate(new Vector3(0, 120, 0) * Time.deltaTime);
}
//add body part when colliding with head
void OnTriggerEnter(Collider other){
if (other.gameObject.CompareTag("Head")){
//start particles
particles.GetComponent<ParticleSystem>().enableEmission = false;
StartCoroutine(stopParticles());
//play sound
audioSrc.Play();
//hide apple
Destroy(gameObject);
//increase score counter
count++;
//Debug.Log(count);
}
}
//stop particles after collision
IEnumerator stopParticles(){
yield return new WaitForSeconds(0.4f);
//stop particles
particles.GetComponent<ParticleSystem>().enableEmission = false;
}
}
I tried to debug it enters playing line which is wierd !