In my background music script i’ve got 3 conditions, in first - audioclips are playing randomly. The second condition - if player’s health is lower than 25 audio.clip is changed to lowLifeTrack and in 3rd condition when fight boss audio.clip is changed to bossFightTrack.
My problem is that last two conditions dont work properly i can debug them, but music is not playing(((
using UnityEngine;
using System.Collections;
public class audioPlayer : MonoBehaviour {
public AudioClip [] soundTrack;
public AudioClip bossFightTrack;
public AudioClip lowLifeTrack;
private int currentTrack;
private GameObject objPlayer;
private GameObject sCont;
private SpawnControl sContScript;
private AIscript ptrScriptAI;
// Use this for initialization
void Start () {
objPlayer = (GameObject) GameObject.FindWithTag ("Player");
sCont = (GameObject) GameObject.FindWithTag ("SpawnerControl");
sContScript = (SpawnControl) sCont.GetComponent( typeof(SpawnControl));
}
// Update is called once per frame
void Update () {
AIscript ptrScriptAI = (AIscript) objPlayer.gameObject.GetComponent(typeof(AIscript) );
if(soundTrack.Length == 0)
return;
if(!audio.isPlaying){
currentTrack= Random.Range(0, soundTrack.Length);
audio.clip = soundTrack[currentTrack];
audio.Play();
}
if(ptrScriptAI.health<25){
print("lowLife");
audio.clip = lowLifeTrack;
audio.Play();
}
if(sContScript.wavesCompleted>0){
print("bossFight");
audio.clip = bossFightTrack;
audio.Play();
}
}
}