playing multiple sound on gameobject
I did follow other post which I need to make an array for audio source, but for some reason, it's only playing array [0].
below is my code:
 AudioSource lowHPSE; //SE = Sound Effect
 AudioSource lowAmmoSE;
 
     void Start() {
         AudioSource[] audios = GetComponents<AudioSource> ();
         lowHPSE = audios [0];
         lowAmmoSE = audios [1];
     }
 
     void Update () {
         AlmostDead ();
         lowAmmoLeft ();
     }
 
     void AlmostDead () {
         if (health.currentHP == health.healthCritical) {
             lowHPSE.Play ();
         }
     }
 
     void lowAmmoLeft () {
         if (ammoSE.currentAmmo == ammoSE.ammoLow) {
             lowAmmoSE.Play ();
         }
     }
right now, when conditions are met, it's only playing sound for lowHPSE. The audio source orders in inspector is lowHPSE, then lowAmmoSE.
How do I play lowAmmoSE, the second audio source?
Answer by josh15 · Nov 24, 2016 at 06:20 PM
I am not good in scripting but i can show you how make in my Script [RequireComponent(typeof(AudioSource))]// Before the class began public AudioClip[] audioClip; void update(){ anim.SetBool("isWalking", true); anim.SetBool("isAttacking", false);
             stopSound(1); stopSound(0);
} public void playSound(int clip) { GetComponent().clip = audioClip[clip]; // GetComponent().loop = true; GetComponent().Play(); } public void stopSound(int clip) { GetComponent().clip = audioClip[clip]; // GetComponent().loop = true; GetComponent().Stop(); }
it's like that and it is work with me play randomly
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                