###困っていること
自作した関数が呼び出されてはいるみたいだが、音がならない。
###環境
Unity2018 2.4f1
###ソースコード
C#
1//GameManager.cs 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using DG.Tweening; 6 7public class BatteryChecker : MonoBehaviour { 8 bool state = false; 9 int lockint = 0; //unlock=0 lock=1 10 public GameObject Button; 11 public GameObject GameManager; 12 public GameObject VoiceManager; 13 int toutyaku = 0; 14 int BatteryFull = 0; 15 16 17 18 // Update is called once per frame 19 void Update() 20 { 21 22 string bstatus = string.Format("{0}", SystemInfo.batteryStatus); 23 if (bstatus == "Charging" && state == false) //キーをON 24 { 25 state = true; 26 Debug.Log("The key ON!!!!"); 27 GameManager.GetComponent<GameManager>().ButtonDestroy(); // 28 Debug.Log("出発!"); 29 toutyaku = 1; 30 } 31 if (bstatus == "Discharging" && toutyaku == 1) //到着 32 { 33 toutyaku = 0; 34 VoiceManager.GetComponent<VoiceManager>().ArrivedVoice(); 35 GameManager.GetComponent<GameManager>().InstantiateButton(); 36 Debug.Log("到着"); 37 38 } 39 40 if (bstatus == "Full" && BatteryFull == 0 && state == true) //バッテリーフル充電 41 { 42 BatteryFull = 1; //到着したときにリセットする 43 DOVirtual.DelayedCall(30.0f, () => 44 { 45 VoiceManager.GetComponent<VoiceManager>().BatteryFullChargeVoice(); 46 47 }); 48 } 49 } 50 51 public void Deperture() 52 { 53 state = true; 54 Debug.Log("The key ON!!!!"); 55 GameManager.GetComponent<GameManager>().ButtonDestroy(); 56 Debug.Log("出発!"); 57 58 } 59 60 public void Arrive() 61 { 62 VoiceManager.GetComponent<VoiceManager>().ArrivedVoice(); 63 GameManager.GetComponent<GameManager>().InstantiateButton(); 64 } 65 66} 67
C#
1/VoiceManager.cs 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5using UnityEngine.UI; 6 7public class VoiceManager : MonoBehaviour { 8 public float SumTime; 9 public float RestTime; 10 public float RandomTime; 11 public float RTempTime; 12 public bool lockbool = false; //起動している間のみTRUE。鳴らしたくないときはFalse 13 public int moddd; 14 //出勤1 退勤2 休憩行き3 休憩帰り4 ツーリング行き5 ツーリング帰り6 15 16 //X_Y1 X...出勤退勤ツーリングの頭文字 17 //Y出発ボイス(D)なのか到着ボイス(T)なのか 18 //番号はボイス識別番号 19 public AudioClip S_D1; 20 public AudioClip S_T1; 21 22 public AudioClip T_D1; 23 public AudioClip T_T1; 24 25 private AudioSource audiosource; 26 27 void Awake() 28 { 29 RandomTime = Random.Range(180.0f, 480.0f); 30 moddd = ModeSaver.mode; 31 Debug.Log(moddd + "VMno"); 32 audiosource = gameObject.GetComponent<AudioSource>(); 33 34 } 35 36 void Start() 37 { 38 39 } 40 41 void Update() 42 { 43 SumTime += Time.deltaTime; 44 RestTime += Time.deltaTime; 45 RTempTime += Time.deltaTime; 46 if (lockbool == true) 47 { 48 if (RestTime >= 3600.0f) //休憩促し 49 { 50 RestVoice(); 51 } 52 if (RTempTime >= RandomTime) //ぼやき 53 { 54 RandomVoice(); 55 } 56 } 57 58 } 59 60 public void unlock() 61 { 62 lockbool = true; 63 } 64 65 public void locking() 66 { 67 lockbool = false; 68 } 69 70 71 72 //出勤1 退勤2 休憩行き3 休憩帰り4 ツーリング行き5 ツーリング帰り6 73 public void ArrivedVoice() 74 { 75 switch(moddd) 76 { 77 case 1: //出勤 78 GetComponent<AudioSource>().PlayOneShot(S_T1); 79 Debug.Log("arrivemode = 1"); 80 break; 81 case 2://退勤 82 GetComponent<AudioSource>().PlayOneShot(T_T1); 83 Debug.Log("arrivemode = 2"); 84 break; 85 default: 86 Debug.Log("出勤退勤モードじゃないっす。"); 87 break; 88 } 89 } 90 91 public void DepertureVoice(int mode) 92 { 93 if (mode == 1) 94 { 95 Debug.Log("dmode = 1"); 96 GetComponent<AudioSource>().PlayOneShot(S_D1); 97 } 98 else if (mode == 2) { 99 GetComponent<AudioSource>().PlayOneShot(T_D1); 100 Debug.Log("dmode = 2"); 101 } 102 else 103 { 104 Debug.Log("失敗" + mode); 105 } 106 107 } 108} 109
動きとしてはGameManagerによってVoiceManager.DepertureVoice()が呼び出され、S_D1.wavが再生される
確認しているものとしてはコンソールにdmode = 1は帰ってくる。しかし、S_D1は再生されないdmode = 2のときも同様
また、数秒後に呼ばれるArrivedVoiceは正常に動作する。
また、VoiceManagerオブジェクトにはVoiceManager.csとすべての音声がアタッチされている。
エラーコードは出ない。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/26 12:02
2018/08/26 12:05