Level Change Annunciation
I am developing a fairly large game, 1000 levels. I have built the levels and the scripts that allow traversal. Each level change is vocalized using small wav files. I am looking for an optimization trick. Currently I have 1000 if statements. Surely there is a better, faster, more efficient and less space taking way to do what I am doing. Any help would be appreciated.
if (SceneManager.GetActiveScene().buildIndex == 2)
{
// sectorText.text = "0000";
compAudio.playAudio(95); // Sector
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(0); // ZERO
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(44); // Fed Space
}
if (SceneManager.GetActiveScene().buildIndex == 3)
{
// sectorText.text = "0001";
compAudio.playAudio(95); // Sector
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(1); // ONE
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(44); // Fed Space
}
if (SceneManager.GetActiveScene().buildIndex == 4)
{
//sectorText.text = "0002";
compAudio.playAudio(95); // Sector
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(2); // TWO
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(73); // Neutral Space
}
.
.
.
if (SceneManager.GetActiveScene().buildIndex == 1000)
{
//sectorText.text = "1000";
compAudio.playAudio(95); // Sector
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(1); // ONE
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(56); // THOUSAND
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(73); // Neutral Space
}
Cheers, Mark
You can try somthing like this:
int num = Scene$$anonymous$$anager.GetActiveScene().buildIndex;
//Play the sector Sound
compAudio.playAudio(95); // Sector
yield return new WaitForSeconds(myAudio.clip.length);
if (num > 10 && num < 20)
compAudio.playAudio(0); // ZERO
if (num > 20 && num < 30)
compAudio.playAudio(1); // One
if (num > 30 && num < 10)
compAudio.playAudio(2); // Two
yield return new WaitForSeconds(myAudio.clip.length);
compAudio.playAudio(44); // Fed Space
Answer by Mad_Mark · Apr 14, 2018 at 06:52 AM
Never mind. Figured it out. I used: if (sectorInt == 1000) { compAudio.playAudio(1); // ONE yield return new WaitForSeconds(myAudio.clip.length); compAudio.playAudio(29); // THOUSAND yield return new WaitForSeconds(myAudio.clip.length); } else if (sectorInt >= 900) { compAudio.playAudio(9); // NINE yield return new WaitForSeconds(myAudio.clip.length); compAudio.playAudio(28); // Hundred yield return new WaitForSeconds(myAudio.clip.length);
newSectorInt = sectorInt - 900;
Debug.Log("sectorint is in 900's. newsectorint = " + newSectorInt);
}
and then just continued looking for tens and ones. Mark