Question by
KnightRiderGuy · Dec 15, 2015 at 02:48 AM ·
c#audioproblem during runtimeaudio.playoneshotbuttonstates
Why does my audio get messed up in the last part of this script?
OK this is weird, my messages are being displayed sort of OK although the "ButtonState01" "SCANNING" message reappears when It shouldn't?
But most of all why in the last part of my script when I call the "GoodbyeUser" message does my oneShot audio clip sound all weird like its a stretched out Cylon robot for lack of a better description?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MessageCentreManager : MonoBehaviour {
int sysHour = System.DateTime.Now.Hour; //gives you the current hour as an integer.
//UI Text Reference
public Text MessageCentreText;
//Random Clips
public AudioClip[] goodNightVoices;
public AudioClip[] goodAfternoonVoices;
public AudioClip[] goodDayVoices;
//Button States
public int buttonState = 0;
bool GreetUser = true;
bool GoodbyeUser = false;
void Update ()
{
if (GreetUser) StartCoroutine(ShowGreeting());
else if (GoodbyeUser) StartCoroutine(GreetUser2());
else
{
if (buttonState == 1) MessageCentreText.text = "SCANNING";
else if (buttonState == 2) MessageCentreText.text = "AUTO PHONE";
else if (buttonState == 3) MessageCentreText.text = "INT TEMP";
else if (buttonState == 4) MessageCentreText.text = "LASER FIRE";
else if (buttonState == 5) MessageCentreText.text = "TURBO MODE";
else if (buttonState == 6) MessageCentreText.text = "OIL SLICK";
else if (buttonState == 7) MessageCentreText.text = "AUTO SCAN";
else if (buttonState == 8) MessageCentreText.text = "TRIP TIME";
else if (buttonState == 9) MessageCentreText.text = "RADAR";
else if (buttonState == 10) MessageCentreText.text = "CNTDWN TIMER";
else if (buttonState == 11) MessageCentreText.text = "EXT MOVIE PLAYER";
else if (buttonState == 12) MessageCentreText.text = "GRAPL HOOK LAUNCH";
else if (buttonState == 13) MessageCentreText.text = "AUTO DOOR LFT";
else if (buttonState == 14) MessageCentreText.text = "AUTO DOOR RHT";
else if (buttonState == 15) MessageCentreText.text = "PENG";
else if (buttonState == 16) MessageCentreText.text = "7DLA";
else if (buttonState == 17) MessageCentreText.text = "6RM";
else if (buttonState == 18) MessageCentreText.text = "FOG LHTS";
else if (buttonState == 19) MessageCentreText.text = "HEAD LHTS";
else if (buttonState == 20) MessageCentreText.text = "REAR HATCH";
else if (buttonState == 21) MessageCentreText.text = "HIGH BEAMS";
else if (buttonState == 22) MessageCentreText.text = "RHT WIN UP";
else if (buttonState == 23) MessageCentreText.text = "RHT WIN DWN";
else if (buttonState == 24) MessageCentreText.text = "LFT WIN UP";
else if (buttonState == 25) MessageCentreText.text = "LFT WIN DWN";
}
}
IEnumerator ShowGreeting()
{
if (GreetUser) ShowGreeting();
GoodbyeUser = false;
//Time OF Day Notification
//Morning Time
if (sysHour >= 01 && sysHour <= 12) {
MessageCentreText.text = "GOOD MORNING";
Debug.Log ("Good Morning!");
}
//Noon Time
if (sysHour >= 12 && sysHour <= 18) {
MessageCentreText.text = "GOOD AFTERNOON";
Debug.Log ("Good Afternoon!");
}
//Night Time
if (sysHour >= 18 && sysHour <= 24) {
MessageCentreText.text = "GOOD EVENING";
Debug.Log ("Good Evening!");
}
/*else {
//Do something if desired
MessageCentreText.text = "KNIGHT INDUSTRIES 2000";
Debug.Log ("KNIGHT INDUSTRIES 2000");
}*/
yield return new WaitForSeconds(5); //Wait 5 seconds
GreetUser = false;
}
//Scanner Button For Message
public void GoScannerMessage()
{
buttonState = 1;
}
//Car Phone Button For Message
public void GoAutoPhoneMessage()
{
buttonState = 2;
}
//Temperature Button For Message
public void GoTemperatureMessage()
{
buttonState = 3;
}
//Laser Button For Message
public void GoLaserMessage()
{
buttonState = 4;
}
//Turbo Boost Button For Message
public void GoTurboBoostMessage()
{
buttonState = 5;
}
//Oil Slick Button For Message
public void GoOilSlickMessage()
{
buttonState = 6;
}
//Surveillance Mode Button For Message
public void GoSurveillanceModeMessage()
{
buttonState = 7;
}
//Trip Timere Button For Message
public void GoTripTimerMessage()
{
buttonState = 8;
}
//Radar Button For Message
public void GoRadarMessage()
{
buttonState = 9;
}
//Countdown Timer Button For Message
public void GoCountdownTimerMessage()
{
buttonState = 10;
}
//Movie Player Button For Message
public void GoMoviePlayerMessage()
{
buttonState = 11;
}
//Grappling Hook Button For Message
public void GoGrapplingHookMessage()
{
buttonState = 12;
}
//Auto Door Left Button For Message
public void GoAutoDoorLeftMessage()
{
buttonState = 13;
}
//Auto Door Right Button For Message
public void GoAutoDoorRightMessage()
{
buttonState = 14;
}
//PENG Button For Message
public void GoPENGButtonMessage()
{
buttonState = 15;
}
//7DLA Button For Message
public void Go7DLAButtonMessage()
{
buttonState = 16;
}
//6RM Button For Message
public void Go6RMButtonMessage()
{
buttonState = 17;
}
//Fog Lights Button For Message
public void GoFogLightsButtonMessage()
{
buttonState = 18;
}
//Head Lights Button For Message
public void GoHeadLightsButtonMessage()
{
buttonState = 19;
}
//Rear Hatch Button For Message
public void GoRearHatchButtonMessage()
{
buttonState = 20;
}
//High Beams Button For Message
public void GoHighBeamsButtonMessage()
{
buttonState = 21;
}
//Right Window Up Button For Message
public void GoRwinUpButtonMessage()
{
buttonState = 22;
}
//Right Window Down Button For Message
public void GoRwinDwnButtonMessage()
{
buttonState = 23;
}
//Left Window Up Button For Message
public void GoLwinUpButtonMessage()
{
buttonState = 24;
}
//Left Window Down Button For Message
public void GoLwinDwnButtonMessage()
{
buttonState = 25;
}
//Application Quit Button
public void GoQuitApplication(){
StartCoroutine(GreetUser2());
}
IEnumerator GreetUser2()
{
if (GoodbyeUser) GreetUser2();
GreetUser = false;
GoodbyeUser = true;
//Time OF Day Notification
//Morning Time
if (sysHour >= 01 && sysHour <= 12) {
AudioClip randomClip = goodDayVoices [UnityEngine.Random.Range (0, goodDayVoices.Length)];
//Play that sound.
GetComponent<AudioSource> ().PlayOneShot (randomClip);
MessageCentreText.text = "HAVE A NICE DAY";
Debug.Log ("Have a Nice Day!");
}
//Noon Time
if (sysHour >= 12 && sysHour <= 18) {
MessageCentreText.text = "HAVE A GOOD AFTERNOON";
AudioClip randomClip = goodAfternoonVoices [UnityEngine.Random.Range (0, goodAfternoonVoices.Length)];
//Play that sound.
GetComponent<AudioSource> ().PlayOneShot (randomClip);
Debug.Log ("Have a Good Afternoon!");
}
//Night Time
if (sysHour >= 18 && sysHour <= 24) {
MessageCentreText.text = "GOOD NIGHT";
AudioClip randomClip = goodNightVoices [UnityEngine.Random.Range (0, goodNightVoices.Length)];
//Play that sound.
GetComponent<AudioSource> ().PlayOneShot (randomClip);
Debug.Log ("Good Night!");
}
yield return new WaitForSeconds(3.1f); // wait time
Application.Quit();
}
}
Comment