hey folks! i´ve got a weird problem. can anyone find an error and a reason why my sound shouldn´t play?
////////////////////// script snippet 1
/// all the var stuff - all this is working correctly
//....
function Update(){
if(currEnergy <= 0.0){
currEnergy = 0;
//Application.LoadLevel("start_menue");
}
else if (currEnergy <= MaxEnergy){
currEnergy = currEnergy + (Time.deltaTime*BarRegenerationFactor) ;
}
else if (currEnergy >= MaxEnergy){
currEnergy = MaxEnergy;
}
currEnergy = Mathf.Max(0.0, currEnergy);
EnergyPercent = Mathf.Max(0.0, Mathf.RoundToInt(currEnergy/MaxEnergy*100));
Debug.Log(EnergyPercent); // yes... all this stuffs works absolute correctly
}
////////////////////// script snippet 2
var lowEnergyAlertSound: GameObject; // is an attached gameobject which contains the sound
private var conToPlr;
var ShipContainer:GameObject;
function Update(){
conToPlr = ShipContainer.GetComponent("player_EnerCal");
if(conToPlr.EnergyPercent <= 25){
lowEnergyAlertSound.audio.Play();
Debug.Log("if conToPlr.EnergyPercent <= 25, this appears but plays no sound and no error appears");
}
//lowEnergyAlertSound.audio.Play(); not working, too....tryed different sound files
}
i already got it playing but i used percent in a range of 0 to 1 and checkt 0.25 as the “alert border”. i thougt 100 % should be 100% and updated it…after that the sound file isn´t playing anymore.
yes, the gameobject is attached.
yes, the soundfile isn´t empty or to low…or to quiet
as i already said…i got it working, but i don´t understand why it is not playing anymore Oo
do you have a plugin that fires off sounds for some reason (like gamekit, gamecenter, OF, …)?
if so ensure that you hook it up correctly so sound is correctly disabled and reenabled.
as another, not that likely alternative, yet still one: are you sure that the media volume of your device is > 0? (media and ringtone are handled seperately)
so, the volume is >0…of course… i switched back to the “percent range 0 - 1”- version, é voila… it works again.
i didn´t change anything to the sound.
for the player nothing has changed, except a playing alert sound.
the difference between the codes
energy calculation script:
nope, i never changed the distance, all i did was in script 1: ShieldPercent = currShield/MaxShield; and checked in script 2 the ShieldPercent if (blablaScript.ShieldPercent < 0.25) sound.audio.Play(); this was working.
version 2: script 1 ShieldPercent = (currShield/MaxShield) * 100; script 2 if (blablaScript.ShieldPercent < 25) sound.audio.Play(); didn´t work
…i´m not sure why this appears, maybe i was overlooking something else somewhere in script 2 which was no syntax error… anyway, i still have a 100% working solution, but thanks for the suggestions!